Skip to content

Commit

Permalink
fixup: add compat layer on setting.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-psb committed Dec 7, 2024
1 parent 4945ded commit f0462dc
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions pulpcore/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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__)
Expand Down

0 comments on commit f0462dc

Please sign in to comment.