From c32c5c4ad98bf75906c426717523de1fd836383f Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Tue, 20 May 2025 14:43:37 +0500 Subject: [PATCH 01/13] fix: Fixing `get_storage` functionality as per new django52. --- test_settings.py | 8 -------- user_tasks/conf.py | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/test_settings.py b/test_settings.py index 8ec72147..b675ee0b 100644 --- a/test_settings.py +++ b/test_settings.py @@ -77,11 +77,3 @@ def root(*args): 'APP_DIRS': True, } ] - -USE_TZ = True - -STORAGES = { - "default": { - "BACKEND": "django.core.files.storage.FileSystemStorage", - }, -} diff --git a/user_tasks/conf.py b/user_tasks/conf.py index 60d169fc..f6d620d4 100644 --- a/user_tasks/conf.py +++ b/user_tasks/conf.py @@ -5,16 +5,31 @@ from datetime import timedelta from django.conf import settings as django_settings +from django.core.files.storage import default_storage as django_default_storage from django.core.files.storage import storages +from django.utils.module_loading import import_string from user_tasks import filters def get_storage(import_path=None): """ - Get the default storage backend or for the given import path. + Return a storage backend instance. + + 1. Explicit import path, if provided. + 2. STORAGES['user_task_artifacts'] alias (Django ≥4.2). + 3. Django’s default_storage singleton. """ - return storages["default"] if import_path is None else storages[import_path] + if import_path: + return import_string(import_path)() + + # New STORAGES dict lookup for user task artifacts + storages_config = getattr(settings, 'STORAGES', {}) + if "user_task_artifacts" in storages_config: + return storages["user_task_artifacts"] + + # Final fallback + return django_default_storage class LazySettings(): @@ -46,6 +61,7 @@ def USER_TASKS_ARTIFACT_STORAGE(self): # pylint: disable=invalid-name import_path = getattr(django_settings, 'USER_TASKS_ARTIFACT_STORAGE', None) return get_storage(import_path) + @property def USER_TASKS_MAX_AGE(self): # pylint: disable=invalid-name """ From 639848b0c7eb956004b0a48adb4c351026ba301f Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Tue, 20 May 2025 15:04:32 +0500 Subject: [PATCH 02/13] fix: Fixing `get_storage` functionality as per new django52. --- test_settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test_settings.py b/test_settings.py index b675ee0b..fddfdce0 100644 --- a/test_settings.py +++ b/test_settings.py @@ -77,3 +77,5 @@ def root(*args): 'APP_DIRS': True, } ] + +USE_TZ = True From aae3c2c2cb60a30a6a5e2ca6d55e81cf355dd079 Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Tue, 20 May 2025 15:06:15 +0500 Subject: [PATCH 03/13] fix: Fixing `get_storage` functionality as per new django52. --- CHANGELOG.rst | 8 ++++++++ user_tasks/__init__.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d0c9c8ff..5cd040b0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,14 @@ Change Log Unreleased ~~~~~~~~~~ +[3.4.1] - 2025-04-20 +~~~~~~~~~~~~~~~~~~~~ + +Changed ++++++++ +* Fix `get_storage` method. + + [3.4.0] - 2025-04-05 ~~~~~~~~~~~~~~~~~~~~ diff --git a/user_tasks/__init__.py b/user_tasks/__init__.py index ebb41f85..2c00bbed 100644 --- a/user_tasks/__init__.py +++ b/user_tasks/__init__.py @@ -4,7 +4,7 @@ from django.dispatch import Signal -__version__ = '3.4.0' +__version__ = '3.4.1' # This signal is emitted when a user task reaches any final state: From c889881e694268dba4ba7880527125864176d138 Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Tue, 20 May 2025 15:33:28 +0500 Subject: [PATCH 04/13] fix: Fixing `get_storage` functionality as per new django52. --- test_settings.py | 13 ++++++++++ tests/test_storages.py | 55 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/test_storages.py diff --git a/test_settings.py b/test_settings.py index fddfdce0..b4e4af6c 100644 --- a/test_settings.py +++ b/test_settings.py @@ -79,3 +79,16 @@ def root(*args): ] USE_TZ = True + +STORAGES = { + "default": { + "BACKEND": "django.core.files.storage.FileSystemStorage", + }, + "user_task_artifacts": { + "BACKEND": "storages.backends.s3boto3.S3Boto3Storage", + "OPTIONS": { + "bucket_name": "tasks", + "location": "tasks/images", + } + } +} diff --git a/tests/test_storages.py b/tests/test_storages.py new file mode 100644 index 00000000..eef85eb3 --- /dev/null +++ b/tests/test_storages.py @@ -0,0 +1,55 @@ +from storages.backends.s3boto3 import S3Boto3Storage + +from django.core.files.storage import FileSystemStorage +from django.test import TestCase, override_settings + +from user_tasks.conf import get_storage +from user_tasks.conf import settings as user_tasks_settings + + +class TestUserTaskStatus(TestCase): + + @override_settings( + USER_TASKS_ARTIFACT_STORAGE="storages.backends.s3boto3.S3Boto3Storage" + ) + def test_storage_from_import_path(self): + """ + Test that providing an explicit import path to get_storage() + returns the correct storage backend. + """ + storage = get_storage("storages.backends.s3boto3.S3Boto3Storage") + assert isinstance(storage, S3Boto3Storage) + + def test_storage_fallback_to_default(self): + """ + Test that get_storage() returns Django's default storage + when no import path is provided and no STORAGES dict is defined. + """ + storage = get_storage() + assert isinstance(storage, FileSystemStorage) + + def test_storage_from_storages_dict(self): + """ + Test that get_storage() returns the storage instance defined + under STORAGES["user_task_artifacts"] when present. + + Since LazySettings does not expose STORAGES from Django settings directly, + we monkey-patch it on the user_tasks_settings object. + """ + setattr(user_tasks_settings, 'STORAGES', { + "default": { + "BACKEND": "django.core.files.storage.FileSystemStorage", + }, + "user_task_artifacts": { + "BACKEND": "storages.backends.s3boto3.S3Boto3Storage", + "OPTIONS": { + "bucket_name": "tasks", + "location": "tasks/images", + } + } + }) + + storage = get_storage() + assert isinstance(storage, S3Boto3Storage) + assert storage.default_acl == "public" + assert storage.location == "tasks/images" From 86cc14c4340d538f3a1d14cd946be22cf47420f5 Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Tue, 20 May 2025 15:36:02 +0500 Subject: [PATCH 05/13] fix: Fixing `get_storage` functionality as per new django52. --- tests/test_storages.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_storages.py b/tests/test_storages.py index eef85eb3..b734040f 100644 --- a/tests/test_storages.py +++ b/tests/test_storages.py @@ -51,5 +51,4 @@ def test_storage_from_storages_dict(self): storage = get_storage() assert isinstance(storage, S3Boto3Storage) - assert storage.default_acl == "public" assert storage.location == "tasks/images" From 30421bcbb202118d2763c209eddf5b0bc0ecc4b2 Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Tue, 20 May 2025 15:42:42 +0500 Subject: [PATCH 06/13] fix: Fixing `get_storage` functionality as per new django52. --- requirements/test.in | 1 + requirements/test.txt | 3 +++ 2 files changed, 4 insertions(+) diff --git a/requirements/test.in b/requirements/test.in index 03b89957..945351d0 100644 --- a/requirements/test.in +++ b/requirements/test.in @@ -9,3 +9,4 @@ pytest-cov # pytest extension for code coverage statistics pytest-django # pytest extension for better Django support rules # Authorization rules for test cases testfixtures # Provides the LogCapture utility used in some tests +django-storages \ No newline at end of file diff --git a/requirements/test.txt b/requirements/test.txt index e7798a4f..f6bc2bff 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -45,10 +45,13 @@ coverage[toml]==7.8.0 # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt # -r requirements/base.txt # django-model-utils + # django-storages # djangorestframework # drf-yasg django-model-utils==5.0.0 # via -r requirements/base.txt +django-storages==1.14.6 + # via -r requirements/test.in # via # -r requirements/base.txt # drf-yasg From a48568478b8b805e7bef52342e1c064df8235304 Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Tue, 20 May 2025 15:44:06 +0500 Subject: [PATCH 07/13] fix: Fixing `get_storage` functionality as per new django52. --- requirements/base.txt | 4 ++-- requirements/ci.txt | 10 +++++----- requirements/dev.txt | 21 ++++++++++++--------- requirements/doc.txt | 20 ++++---------------- requirements/pip-tools.txt | 2 +- requirements/pip.txt | 2 +- requirements/quality.txt | 8 ++++---- 7 files changed, 29 insertions(+), 38 deletions(-) diff --git a/requirements/base.txt b/requirements/base.txt index 1e5f67e3..3d0a886e 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -14,7 +14,7 @@ celery==5.5.2 # via # -c requirements/constraints.txt # -r requirements/base.in -click==8.1.8 +click==8.2.0 # via # celery # click-didyoumean @@ -26,7 +26,7 @@ click-plugins==1.1.1 # via celery click-repl==0.3.0 # via celery -django==4.2.20 +django==4.2.21 # via # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt # -r requirements/base.in diff --git a/requirements/ci.txt b/requirements/ci.txt index ca9c9e0b..ddf9c71c 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -22,15 +22,15 @@ packaging==25.0 # via # pyproject-api # tox -platformdirs==4.3.7 +platformdirs==4.3.8 # via # tox # virtualenv -pluggy==1.5.0 +pluggy==1.6.0 # via tox -pyproject-api==1.9.0 +pyproject-api==1.9.1 # via tox -tox==4.25.0 +tox==4.26.0 # via -r requirements/ci.in -virtualenv==20.30.0 +virtualenv==20.31.2 # via tox diff --git a/requirements/dev.txt b/requirements/dev.txt index 6cab2ab9..b8ef3df6 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -12,7 +12,7 @@ asgiref==3.8.1 # via # -r requirements/test.txt # django -astroid==3.3.9 +astroid==3.3.10 # via # -r requirements/quality.txt # pylint @@ -37,7 +37,7 @@ chardet==5.2.0 # via # -r requirements/ci.txt # tox -click==8.1.8 +click==8.2.0 # via # -r requirements/pip-tools.txt # -r requirements/quality.txt @@ -87,16 +87,19 @@ distlib==0.3.9 # via # -r requirements/ci.txt # virtualenv -django==4.2.20 +django==4.2.21 # via # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt # -r requirements/test.txt # django-model-utils + # django-storages # djangorestframework # drf-yasg # edx-i18n-tools django-model-utils==5.0.0 # via -r requirements/test.txt +django-storages==1.14.6 + # via -r requirements/test.txt djangorestframework==3.16.0 # via # -r requirements/test.txt @@ -168,14 +171,14 @@ pbr==6.1.1 # stevedore pip-tools==7.4.1 # via -r requirements/pip-tools.txt -platformdirs==4.3.7 +platformdirs==4.3.8 # via # -r requirements/ci.txt # -r requirements/quality.txt # pylint # tox # virtualenv -pluggy==1.5.0 +pluggy==1.6.0 # via # -r requirements/ci.txt # -r requirements/test.txt @@ -211,7 +214,7 @@ pylint-plugin-utils==0.8.2 # -r requirements/quality.txt # pylint-celery # pylint-django -pyproject-api==1.9.0 +pyproject-api==1.9.1 # via # -r requirements/ci.txt # tox @@ -256,7 +259,7 @@ six==1.17.0 # -r requirements/test.txt # edx-lint # python-dateutil -snowballstemmer==2.2.0 +snowballstemmer==3.0.1 # via # -r requirements/quality.txt # pydocstyle @@ -278,7 +281,7 @@ tomlkit==0.13.2 # via # -r requirements/quality.txt # pylint -tox==4.25.0 +tox==4.26.0 # via -r requirements/ci.txt tzdata==2025.2 # via @@ -294,7 +297,7 @@ vine==5.1.0 # amqp # celery # kombu -virtualenv==20.30.0 +virtualenv==20.31.2 # via # -r requirements/ci.txt # tox diff --git a/requirements/doc.txt b/requirements/doc.txt index afaa524e..b3e07e02 100644 --- a/requirements/doc.txt +++ b/requirements/doc.txt @@ -38,11 +38,9 @@ celery==5.5.2 # -r requirements/base.txt certifi==2025.4.26 # via requests -cffi==1.17.1 - # via cryptography charset-normalizer==3.4.2 # via requests -click==8.1.8 +click==8.2.0 # via # -r requirements/base.txt # celery @@ -67,11 +65,9 @@ coreapi==2.3.3 # openapi-codec coreschema==0.0.4 # via coreapi -cryptography==44.0.3 - # via secretstorage deepmerge==2.0 # via sphinxcontrib-openapi -django==4.2.20 +django==4.2.21 # via # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt # -r requirements/base.txt @@ -119,10 +115,6 @@ jaraco-context==6.0.1 # via keyring jaraco-functools==4.1.0 # via keyring -jeepney==0.9.0 - # via - # keyring - # secretstorage jinja2==3.1.6 # via # coreschema @@ -168,8 +160,6 @@ prompt-toolkit==3.0.51 # via # -r requirements/base.txt # click-repl -pycparser==2.22 - # via cffi pydata-sphinx-theme==0.15.4 # via sphinx-book-theme pygments==2.19.1 @@ -217,14 +207,12 @@ rich==14.0.0 # via twine roman-numerals-py==3.1.0 # via sphinx -rpds-py==0.24.0 +rpds-py==0.25.0 # via # jsonschema # referencing rules==3.5 # via -r requirements/doc.in -secretstorage==3.3.3 - # via keyring simplejson==3.20.1 # via django-rest-swagger six==1.17.0 @@ -232,7 +220,7 @@ six==1.17.0 # -r requirements/base.txt # python-dateutil # sphinxcontrib-httpdomain -snowballstemmer==2.2.0 +snowballstemmer==3.0.1 # via sphinx soupsieve==2.7 # via beautifulsoup4 diff --git a/requirements/pip-tools.txt b/requirements/pip-tools.txt index 1dd71b5e..bf361d6f 100644 --- a/requirements/pip-tools.txt +++ b/requirements/pip-tools.txt @@ -6,7 +6,7 @@ # build==1.2.2.post1 # via pip-tools -click==8.1.8 +click==8.2.0 # via pip-tools packaging==25.0 # via build diff --git a/requirements/pip.txt b/requirements/pip.txt index a124796a..4497584b 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -12,5 +12,5 @@ pip==24.2 # via # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt # -r requirements/pip.in -setuptools==80.3.1 +setuptools==80.7.1 # via -r requirements/pip.in diff --git a/requirements/quality.txt b/requirements/quality.txt index 20c5cd14..b78ff56f 100644 --- a/requirements/quality.txt +++ b/requirements/quality.txt @@ -4,11 +4,11 @@ # # make upgrade # -astroid==3.3.9 +astroid==3.3.10 # via # pylint # pylint-celery -click==8.1.8 +click==8.2.0 # via # click-log # code-annotations @@ -33,7 +33,7 @@ mccabe==0.7.0 # via pylint pbr==6.1.1 # via stevedore -platformdirs==4.3.7 +platformdirs==4.3.8 # via pylint pycodestyle==2.13.0 # via -r requirements/quality.in @@ -59,7 +59,7 @@ pyyaml==6.0.2 # via code-annotations six==1.17.0 # via edx-lint -snowballstemmer==2.2.0 +snowballstemmer==3.0.1 # via pydocstyle stevedore==5.4.1 # via code-annotations From 6201f3f57883ee576f45184e91d38426a1c687e5 Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Tue, 20 May 2025 15:46:30 +0500 Subject: [PATCH 08/13] fix: Fixing `get_storage` functionality as per new django52. --- requirements/test.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/test.txt b/requirements/test.txt index f6bc2bff..2d882517 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -20,7 +20,7 @@ celery==5.5.2 # via # -c requirements/constraints.txt # -r requirements/base.txt -click==8.1.8 +click==8.2.0 # via # -r requirements/base.txt # celery @@ -75,7 +75,7 @@ packaging==25.0 # -r requirements/test.in # drf-yasg # pytest -pluggy==1.5.0 +pluggy==1.6.0 # via pytest prompt-toolkit==3.0.51 # via From 0de1fe998249d9581899bd5acd8fba7d32a757ad Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Tue, 20 May 2025 15:50:17 +0500 Subject: [PATCH 09/13] fix: Fixing `get_storage` functionality as per new django52. --- requirements/dev.txt | 22 ++++++++++++++++++++++ requirements/test.in | 3 ++- requirements/test.txt | 17 +++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index b8ef3df6..599b5da8 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -21,6 +21,13 @@ billiard==4.2.1 # via # -r requirements/test.txt # celery +boto3==1.38.19 + # via -r requirements/test.txt +botocore==1.38.19 + # via + # -r requirements/test.txt + # boto3 + # s3transfer build==1.2.2.post1 # via # -r requirements/pip-tools.txt @@ -133,6 +140,11 @@ jinja2==3.1.6 # via # -r requirements/quality.txt # code-annotations +jmespath==1.0.1 + # via + # -r requirements/test.txt + # boto3 + # botocore kombu==5.5.3 # via # -r requirements/test.txt @@ -235,6 +247,7 @@ pytest-django==4.11.1 python-dateutil==2.9.0.post0 # via # -r requirements/test.txt + # botocore # celery python-slugify==8.0.4 # via @@ -253,6 +266,10 @@ pyyaml==6.0.2 # edx-i18n-tools rules==3.5 # via -r requirements/test.txt +s3transfer==0.12.0 + # via + # -r requirements/test.txt + # boto3 six==1.17.0 # via # -r requirements/quality.txt @@ -291,6 +308,11 @@ uritemplate==4.1.1 # via # -r requirements/test.txt # drf-yasg +urllib3==2.2.3 + # via + # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt + # -r requirements/test.txt + # botocore vine==5.1.0 # via # -r requirements/test.txt diff --git a/requirements/test.in b/requirements/test.in index 945351d0..a704d951 100644 --- a/requirements/test.in +++ b/requirements/test.in @@ -9,4 +9,5 @@ pytest-cov # pytest extension for code coverage statistics pytest-django # pytest extension for better Django support rules # Authorization rules for test cases testfixtures # Provides the LogCapture utility used in some tests -django-storages \ No newline at end of file +django-storages +boto3 \ No newline at end of file diff --git a/requirements/test.txt b/requirements/test.txt index 2d882517..0bd12398 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -16,6 +16,12 @@ billiard==4.2.1 # via # -r requirements/base.txt # celery +boto3==1.38.19 + # via -r requirements/test.in +botocore==1.38.19 + # via + # boto3 + # s3transfer celery==5.5.2 # via # -c requirements/constraints.txt @@ -63,6 +69,10 @@ inflection==0.5.1 # drf-yasg iniconfig==2.1.0 # via pytest +jmespath==1.0.1 + # via + # boto3 + # botocore kombu==5.5.3 # via # -r requirements/base.txt @@ -92,6 +102,7 @@ pytest-django==4.11.1 python-dateutil==2.9.0.post0 # via # -r requirements/base.txt + # botocore # celery pytz==2025.2 # via @@ -103,6 +114,8 @@ pyyaml==6.0.2 # drf-yasg rules==3.5 # via -r requirements/test.in +s3transfer==0.12.0 + # via boto3 six==1.17.0 # via # -r requirements/base.txt @@ -121,6 +134,10 @@ uritemplate==4.1.1 # via # -r requirements/base.txt # drf-yasg +urllib3==2.2.3 + # via + # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt + # botocore vine==5.1.0 # via # -r requirements/base.txt From 132e8469a5d0eefdfadfabffd03c74db63a71401 Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Tue, 20 May 2025 18:10:33 +0500 Subject: [PATCH 10/13] fix: Fixing `get_storage` functionality as per new django52. --- tests/test_storages.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_storages.py b/tests/test_storages.py index b734040f..da355703 100644 --- a/tests/test_storages.py +++ b/tests/test_storages.py @@ -1,3 +1,4 @@ +""" Storages tests.""" from storages.backends.s3boto3 import S3Boto3Storage from django.core.files.storage import FileSystemStorage @@ -8,7 +9,7 @@ class TestUserTaskStatus(TestCase): - + """ Test cases for storages.""" @override_settings( USER_TASKS_ARTIFACT_STORAGE="storages.backends.s3boto3.S3Boto3Storage" ) @@ -36,6 +37,7 @@ def test_storage_from_storages_dict(self): Since LazySettings does not expose STORAGES from Django settings directly, we monkey-patch it on the user_tasks_settings object. """ + # pylint: disable=literal-used-as-attribute setattr(user_tasks_settings, 'STORAGES', { "default": { "BACKEND": "django.core.files.storage.FileSystemStorage", From 93d07a7d9e11f5657fd2546ed8a0ea8e44733b04 Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Tue, 20 May 2025 18:12:24 +0500 Subject: [PATCH 11/13] fix: Fixing `get_storage` functionality as per new django52. --- tests/test_storages.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_storages.py b/tests/test_storages.py index da355703..7ec76a55 100644 --- a/tests/test_storages.py +++ b/tests/test_storages.py @@ -10,6 +10,7 @@ class TestUserTaskStatus(TestCase): """ Test cases for storages.""" + @override_settings( USER_TASKS_ARTIFACT_STORAGE="storages.backends.s3boto3.S3Boto3Storage" ) From 7a72fd0fef8e5dc033aefee18ccf0539f073849b Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Tue, 20 May 2025 18:14:42 +0500 Subject: [PATCH 12/13] fix: Fixing `get_storage` functionality as per new django52. --- tests/test_storages.py | 4 ++-- user_tasks/conf.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_storages.py b/tests/test_storages.py index 7ec76a55..81e7fa7c 100644 --- a/tests/test_storages.py +++ b/tests/test_storages.py @@ -16,7 +16,7 @@ class TestUserTaskStatus(TestCase): ) def test_storage_from_import_path(self): """ - Test that providing an explicit import path to get_storage() + Test that providing an explicit import path to get_storage() returns the correct storage backend. """ storage = get_storage("storages.backends.s3boto3.S3Boto3Storage") @@ -24,7 +24,7 @@ def test_storage_from_import_path(self): def test_storage_fallback_to_default(self): """ - Test that get_storage() returns Django's default storage + Test that get_storage() returns Django's default storage when no import path is provided and no STORAGES dict is defined. """ storage = get_storage() diff --git a/user_tasks/conf.py b/user_tasks/conf.py index f6d620d4..64e86073 100644 --- a/user_tasks/conf.py +++ b/user_tasks/conf.py @@ -61,7 +61,6 @@ def USER_TASKS_ARTIFACT_STORAGE(self): # pylint: disable=invalid-name import_path = getattr(django_settings, 'USER_TASKS_ARTIFACT_STORAGE', None) return get_storage(import_path) - @property def USER_TASKS_MAX_AGE(self): # pylint: disable=invalid-name """ From b99aca24a16b8e09c167ce27b0d61a97aa7fd3cd Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Thu, 5 Jun 2025 09:41:35 -0400 Subject: [PATCH 13/13] fix: Fixing `get_storage` functionality as per new django52. --- user_tasks/conf.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/user_tasks/conf.py b/user_tasks/conf.py index 64e86073..dca02f27 100644 --- a/user_tasks/conf.py +++ b/user_tasks/conf.py @@ -16,18 +16,18 @@ def get_storage(import_path=None): """ Return a storage backend instance. - 1. Explicit import path, if provided. - 2. STORAGES['user_task_artifacts'] alias (Django ≥4.2). + 1. STORAGES['user_task_artifacts'] alias (Django ≥4.2 or 5.2). + 2. Explicit import path, if provided. 3. Django’s default_storage singleton. """ - if import_path: - return import_string(import_path)() - # New STORAGES dict lookup for user task artifacts storages_config = getattr(settings, 'STORAGES', {}) if "user_task_artifacts" in storages_config: return storages["user_task_artifacts"] + if import_path: + return import_string(import_path)() + # Final fallback return django_default_storage