Skip to content

Commit f0462dc

Browse files
committed
fixup: add compat layer on setting.py
1 parent 4945ded commit f0462dc

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

pulpcore/app/settings.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@
5656
STATIC_URL = "/assets/"
5757
STATIC_ROOT = DEPLOY_ROOT / STATIC_URL.strip("/")
5858

59-
STORAGES = {
60-
"default": {"BACKEND": "pulpcore.app.models.storage.FileSystem"},
61-
"staticfiles": {
62-
# This is django's default, but when customizing STORAGES we need to add explicitly
63-
# https://docs.djangoproject.com/en/4.2/ref/settings/#storages
64-
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
65-
},
66-
}
6759

6860
REDIRECT_TO_OBJECT_STORAGE = True
6961

@@ -371,7 +363,7 @@
371363

372364
# HERE STARTS DYNACONF EXTENSION LOAD (Keep at the very bottom of settings.py)
373365
# Read more at https://www.dynaconf.com/django/
374-
from dynaconf import DjangoDynaconf, Validator # noqa
366+
from dynaconf import DjangoDynaconf, Validator, get_history # noqa
375367

376368
# Validators
377369
storage_validator = (
@@ -481,13 +473,35 @@ def otel_middleware_hook(settings):
481473
api_root_validator,
482474
cache_validator,
483475
sha256_validator,
484-
storage_validator,
485476
unknown_algs_validator,
486477
json_header_auth_validator,
487478
authentication_json_header_openapi_security_scheme_validator,
488479
],
489480
post_hooks=otel_middleware_hook,
490481
)
482+
483+
# begin Compatiblity Layer for DEFAULT_FILE_STORAGE deprecation (remove in 3.85):
484+
#
485+
# 1. Removed DEFAULT_FILE_STORAGE from toplevel setting, because STORAGES and DEFAULT_FILE_STORAGE
486+
# are mutually exclusive. This enables users to migrate to STORAGES before true removal of the
487+
# legacy setting.
488+
# 2. After dropping this compat-layer, put the default STORAGES in the toplevel module, as usual.
489+
# Then, DEFAULT_FILE_STORAGE would not be allowed anymore.
490+
491+
# Dynamically update default storages backend to use Pulp's special class,
492+
# but only in the case the user has not provided an explicit setting for it.
493+
dfstorage_history = get_history(settings, key="DEFAULT_FILE_STORAGE")
494+
django_default_used = (
495+
len(dfstorage_history) == 1 and dfstorage_history[0]["identifier"] == "undefined"
496+
)
497+
if django_default_used:
498+
settings.set("STORAGES.default.BACKEND", "pulpcore.app.models.storage.FileSystem")
499+
500+
settings.validators.register(storage_validator)
501+
settings.validators.validate(only=["STORAGES.default.BACKEND", "REDIRECT_TO_OBJECT_STORAGE"])
502+
503+
# end Compatibility Layer
504+
491505
# HERE ENDS DYNACONF EXTENSION LOAD (No more code below this line)
492506

493507
_logger = getLogger(__name__)

0 commit comments

Comments
 (0)