From 7c2821f005be7e47e6c993c3e3a345f379d3aacc Mon Sep 17 00:00:00 2001 From: Lucy Linder Date: Fri, 19 Jul 2024 11:32:20 +0200 Subject: [PATCH] fix: remove hard-coded overwrite_files in AzureStorage The overwrite_files is True by default, and should be settable from the django settings using AZURE_OVERWRITE_FILES. Removing this override will keep the default behaviour (True), while still allowing users to change it. NOTE: this change is important because django / django-storages changed the semantics of the .exists() function, which now returns whether a path is free for upload (and not whether the file already exists on the remote storage). With overwrite_files set to True, .exists() will now always return False. See https://github.com/jschneier/django-storages/issues/1430 --- django_storage_url/backends/az.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/django_storage_url/backends/az.py b/django_storage_url/backends/az.py index a9ed93e..5a7f479 100644 --- a/django_storage_url/backends/az.py +++ b/django_storage_url/backends/az.py @@ -3,6 +3,7 @@ import furl from storages.backends import azure_storage +from django.conf import settings class AzureStorageFile(azure_storage.AzureStorageFile): @@ -56,7 +57,8 @@ def __init__(self, dsn): self.azure_container = container_name self.azure_ssl = secure_urls self.max_memory_size = 10 * 1024**2 - self.overwrite_files = True + # The default is False in the superclass + self.overwrite_files = getattr(settings, "AZURE_OVERWRITE_FILES", True) self.location = "" self.base_url = str(base_url)