From 1ac9a06195dcd465adbb78390ed745cdee1195c5 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Mon, 2 Dec 2024 16:48:57 +0100 Subject: [PATCH] chore: do not fail if S3 bucket does not handle versions And mention the need of activating versioning in the doc. --- docs/config/storage.md | 2 ++ umap/storage.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/config/storage.md b/docs/config/storage.md index c258088d..d0064e27 100644 --- a/docs/config/storage.md +++ b/docs/config/storage.md @@ -58,4 +58,6 @@ STORAGES = { } ``` +In order to store old versions of a layer, the versioning should be activated in the bucket. + See more about the configuration on the [django-storages documentation](https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html). diff --git a/umap/storage.py b/umap/storage.py index c03d4ccb..677bf7de 100644 --- a/umap/storage.py +++ b/umap/storage.py @@ -7,7 +7,6 @@ from pathlib import Path from botocore.exceptions import ClientError from django.conf import settings from django.contrib.staticfiles.storage import ManifestStaticFilesStorage -from django.core.files.base import File from django.core.files.storage import FileSystemStorage from rcssmin import cssmin from rjsmin import jsmin @@ -77,7 +76,8 @@ class UmapS3(S3Storage): metadata = self.connection.meta.client.head_object( Bucket=self.bucket_name, Key=instance.geojson.name ) - return metadata["VersionId"] + # Do not fail if bucket does not handle versioning + return metadata.get("VersionId", metadata["ETag"]) def make_filename(self, instance): return f"{str(instance.pk)}.geojson"