summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-04-21 09:41:37 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-04-21 09:42:43 +0200
commit1cc2eaf02d2aa64f7ca4ef52f3d9f13381540007 (patch)
treee4e25c1c63085c496de17fbbddf27dbdd0c61451
parent54d5bfa9c5eb3e2936a0e382724869867059fad3 (diff)
[3.2.x] Fixed #32665 -- Fixed caches system check crash when STATICFILES_DIRS is a list of 2-tuples.
Thanks Jared Lockhart for the report. Regression in c36075ac1dddfa986340b1a5e15fe48833322372. Backport of 34d1905712d33e72c76b3a55a4fc24abbd11be6c from main
-rw-r--r--django/core/checks/caches.py9
-rw-r--r--docs/releases/3.2.1.txt4
-rw-r--r--tests/check_framework/test_caches.py29
3 files changed, 38 insertions, 4 deletions
diff --git a/django/core/checks/caches.py b/django/core/checks/caches.py
index 4baa23aeb6..b755e0035a 100644
--- a/django/core/checks/caches.py
+++ b/django/core/checks/caches.py
@@ -27,10 +27,11 @@ def check_cache_location_not_exposed(app_configs, **kwargs):
if not setting:
continue
if name == 'STATICFILES_DIRS':
- paths = {
- pathlib.Path(staticfiles_dir).resolve()
- for staticfiles_dir in setting
- }
+ paths = set()
+ for staticfiles_dir in setting:
+ if isinstance(staticfiles_dir, (list, tuple)):
+ _, staticfiles_dir = staticfiles_dir
+ paths.add(pathlib.Path(staticfiles_dir).resolve())
else:
paths = {pathlib.Path(setting).resolve()}
for alias in settings.CACHES:
diff --git a/docs/releases/3.2.1.txt b/docs/releases/3.2.1.txt
index 76291f57c1..4aece451e1 100644
--- a/docs/releases/3.2.1.txt
+++ b/docs/releases/3.2.1.txt
@@ -47,3 +47,7 @@ Bugfixes
* Fixed a regression in Django 3.2 that stopped the shift-key modifier
selecting multiple rows in the admin changelist (:ticket:`32647`).
+
+* Fixed a bug in Django 3.2 where a system check would crash on the
+ :setting:`STATICFILES_DIRS` setting with a list of 2-tuples of
+ ``(prefix, path)`` (:ticket:`32665`).
diff --git a/tests/check_framework/test_caches.py b/tests/check_framework/test_caches.py
index a3ddfd64e7..3b6b41d442 100644
--- a/tests/check_framework/test_caches.py
+++ b/tests/check_framework/test_caches.py
@@ -91,6 +91,35 @@ class CheckCacheLocationTest(SimpleTestCase):
with self.subTest(setting=setting), self.settings(**settings):
self.assertEqual(check_cache_location_not_exposed(None), [])
+ def test_staticfiles_dirs_prefix(self):
+ root = pathlib.Path.cwd()
+ tests = [
+ (root, root, 'matches'),
+ (root / 'cache', root, 'is inside'),
+ (root, root / 'other', 'contains'),
+ ]
+ for cache_path, setting_path, msg in tests:
+ settings = self.get_settings(
+ 'STATICFILES_DIRS',
+ cache_path,
+ ('prefix', setting_path),
+ )
+ with self.subTest(path=setting_path), self.settings(**settings):
+ msg = self.warning_message % (msg, 'STATICFILES_DIRS')
+ self.assertEqual(check_cache_location_not_exposed(None), [
+ Warning(msg, id='caches.W002'),
+ ])
+
+ def test_staticfiles_dirs_prefix_not_conflict(self):
+ root = pathlib.Path.cwd()
+ settings = self.get_settings(
+ 'STATICFILES_DIRS',
+ root / 'cache',
+ ('prefix', root / 'other'),
+ )
+ with self.settings(**settings):
+ self.assertEqual(check_cache_location_not_exposed(None), [])
+
class CheckCacheAbsolutePath(SimpleTestCase):
def test_absolute_path(self):