From dfea3f13def477a4634e6b63e6f4ed77958aa052 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 6 Dec 2024 18:10:55 +0100 Subject: [PATCH] fixup: properly read gzipped content from S3 We did not find a native way to do this from django-storages API. --- umap/storage.py | 3 ++- umap/tests/test_datalayer_s3.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/umap/storage.py b/umap/storage.py index 8eec28600..d028bec48 100644 --- a/umap/storage.py +++ b/umap/storage.py @@ -2,6 +2,7 @@ import os import shutil import time +from gzip import GzipFile from pathlib import Path from botocore.exceptions import ClientError @@ -106,7 +107,7 @@ def get_version(self, ref, instance): ) except ClientError: raise ValueError(f"Invalid version reference: {ref}") - return data["Body"].read() + return GzipFile(mode="r", fileobj=data["Body"]).read() def get_version_path(self, ref, instance): return self.url(instance.geojson.name, parameters={"VersionId": ref}) diff --git a/umap/tests/test_datalayer_s3.py b/umap/tests/test_datalayer_s3.py index bcdee4a8d..fd044ac15 100644 --- a/umap/tests/test_datalayer_s3.py +++ b/umap/tests/test_datalayer_s3.py @@ -80,7 +80,7 @@ def test_update_should_add_version(map, datalayer): def test_get_version(map, datalayer): assert len(datalayer.versions) == 1 - datalayer.geojson = ContentFile('{"foo": "bar"}', "foo.json") + datalayer.geojson = ContentFile(b'{"foo": "bar"}', "foo.json") datalayer.save() assert len(datalayer.versions) == 2 latest = datalayer.versions[0]["ref"]