From f0462dc865b247d670a2dfeb92eed0311265c358 Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Fri, 6 Dec 2024 18:24:59 -0300 Subject: [PATCH] fixup: add compat layer on setting.py --- pulpcore/app/settings.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/pulpcore/app/settings.py b/pulpcore/app/settings.py index f7da802d0f7..0bbdbb08bb8 100644 --- a/pulpcore/app/settings.py +++ b/pulpcore/app/settings.py @@ -56,14 +56,6 @@ STATIC_URL = "/assets/" STATIC_ROOT = DEPLOY_ROOT / STATIC_URL.strip("/") -STORAGES = { - "default": {"BACKEND": "pulpcore.app.models.storage.FileSystem"}, - "staticfiles": { - # This is django's default, but when customizing STORAGES we need to add explicitly - # https://docs.djangoproject.com/en/4.2/ref/settings/#storages - "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage", - }, -} REDIRECT_TO_OBJECT_STORAGE = True @@ -371,7 +363,7 @@ # HERE STARTS DYNACONF EXTENSION LOAD (Keep at the very bottom of settings.py) # Read more at https://www.dynaconf.com/django/ -from dynaconf import DjangoDynaconf, Validator # noqa +from dynaconf import DjangoDynaconf, Validator, get_history # noqa # Validators storage_validator = ( @@ -481,13 +473,35 @@ def otel_middleware_hook(settings): api_root_validator, cache_validator, sha256_validator, - storage_validator, unknown_algs_validator, json_header_auth_validator, authentication_json_header_openapi_security_scheme_validator, ], post_hooks=otel_middleware_hook, ) + +# begin Compatiblity Layer for DEFAULT_FILE_STORAGE deprecation (remove in 3.85): +# +# 1. Removed DEFAULT_FILE_STORAGE from toplevel setting, because STORAGES and DEFAULT_FILE_STORAGE +# are mutually exclusive. This enables users to migrate to STORAGES before true removal of the +# legacy setting. +# 2. After dropping this compat-layer, put the default STORAGES in the toplevel module, as usual. +# Then, DEFAULT_FILE_STORAGE would not be allowed anymore. + +# Dynamically update default storages backend to use Pulp's special class, +# but only in the case the user has not provided an explicit setting for it. +dfstorage_history = get_history(settings, key="DEFAULT_FILE_STORAGE") +django_default_used = ( + len(dfstorage_history) == 1 and dfstorage_history[0]["identifier"] == "undefined" +) +if django_default_used: + settings.set("STORAGES.default.BACKEND", "pulpcore.app.models.storage.FileSystem") + +settings.validators.register(storage_validator) +settings.validators.validate(only=["STORAGES.default.BACKEND", "REDIRECT_TO_OBJECT_STORAGE"]) + +# end Compatibility Layer + # HERE ENDS DYNACONF EXTENSION LOAD (No more code below this line) _logger = getLogger(__name__)