From c0c81794b9a801130365dc3d547d753fb5bb0baa Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Thu, 12 Dec 2024 14:16:59 -0300 Subject: [PATCH] Add compat layer to enable using STORAGES --- pulpcore/app/apps.py | 5 +++++ pulpcore/app/settings.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/pulpcore/app/apps.py b/pulpcore/app/apps.py index cd9c6bc568..dfea606363 100644 --- a/pulpcore/app/apps.py +++ b/pulpcore/app/apps.py @@ -316,6 +316,11 @@ def _ensure_default_domain(sender, **kwargs): if "core_domain" in table_names: from pulpcore.app.util import get_default_domain + # Workaround for getting the settings udpated by dynaconf (not the django's builtin). + # For some reason, the top-level settings import looks like a cached version from + # before dynaconf do its work, which mismatches value from get_default_domain. + from django.conf import settings + default = get_default_domain() # Cache the default domain # Match the Pulp settings if ( diff --git a/pulpcore/app/settings.py b/pulpcore/app/settings.py index ac42609145..fd7bcf8509 100644 --- a/pulpcore/app/settings.py +++ b/pulpcore/app/settings.py @@ -16,7 +16,9 @@ from pathlib import Path from cryptography.fernet import Fernet +from django.conf import global_settings from django.core.exceptions import ImproperlyConfigured +from django.core.files.storage import storages from django.db import connection from pulpcore import constants @@ -56,7 +58,30 @@ STATIC_URL = "/assets/" STATIC_ROOT = DEPLOY_ROOT / STATIC_URL.strip("/") -DEFAULT_FILE_STORAGE = "pulpcore.app.models.storage.FileSystem" +# begin compatilibity layer for DEFAULT_FILE_STORAGE +# Remove on pulpcore=3.85 or pulpcore=4.0 + +# - What is this? +# 1. We shouldnt use STORAGES or DEFAULT_FILE_STORAGE directly because those are +# mutually exclusive by django, which constraints users to use whatever we use. +# This is a hack/workaround to set Pulp's default while still enabling users to choose +# the legacy or the new storage setting. +# 2. The storages patch is to make things consistent. In django that's a cached property +# which was always getting django's default storage, not Pulp's. +_DEFAULT_FILE_STORAGE = "pulpcore.app.models.storage.FileSystem" +_STORAGES = { + "default": { + "BACKEND": "pulpcore.app.models.storage.FileSystem", + }, + "staticfiles": { + "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage", + }, +} + +setattr(global_settings, "DEFAULT_FILE_STORAGE", _DEFAULT_FILE_STORAGE) +setattr(global_settings, "STORAGES", _STORAGES) +# end DEFAULT_FILE_STORAGE deprecation layer + REDIRECT_TO_OBJECT_STORAGE = True WORKING_DIRECTORY = DEPLOY_ROOT / "tmp" @@ -486,6 +511,8 @@ def otel_middleware_hook(settings): post_hooks=otel_middleware_hook, ) # HERE ENDS DYNACONF EXTENSION LOAD (No more code below this line) +storages._backends = settings.STORAGES.copy() +storages.backends _logger = getLogger(__name__)