chore: do not fail if S3 bucket does not handle versions

And mention the need of activating versioning in the doc.
This commit is contained in:
Yohan Boniface 2024-12-02 16:48:57 +01:00
parent 249367fd3a
commit 1ac9a06195
2 changed files with 4 additions and 2 deletions

View file

@ -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).

View file

@ -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"