Skip to content

Commit

Permalink
Add compat layer to enable using STORAGES
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-psb committed Dec 12, 2024
1 parent e3cbeda commit c0c8179
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pulpcore/app/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
29 changes: 28 additions & 1 deletion pulpcore/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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__)

Expand Down

0 comments on commit c0c8179

Please sign in to comment.