Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.6.x] Fixed #21750 -- Fixed regression introduced by 4befb30.

Validating STATIC_ROOT in StaticFilesStorage.__init__ turned out to be
problematic - especially with tests - because the storage refuses to work even
if there are no actual interactions with the file system, which is backward
incompatible.

Originally the validation happened in the StaticFilesStorage.path method, but
that didn't work as expected because the call to FileSystemStorage.__init__
replaced the empty value by a valid path. The new approach is to move back the
check to the StaticFilesStorage.path method, but ensure that the location
attribute remains None after the call to super.

Refs #21581.

Backport of 1e9e735 from master
  • Loading branch information...
commit 6728f159f060e536f1543b4afecb602b6693babb 1 parent bd3af2e
Loic Bistuer authored January 09, 2014 timgraham committed January 11, 2014
2  django/contrib/staticfiles/finders.py
@@ -57,7 +57,7 @@ def __init__(self, apps=None, *args, **kwargs):
57 57
                 prefix, root = root
58 58
             else:
59 59
                 prefix = ''
60  
-            if os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
  60
+            if settings.STATIC_ROOT and os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
61 61
                 raise ImproperlyConfigured(
62 62
                     "The STATICFILES_DIRS setting should "
63 63
                     "not contain the STATIC_ROOT setting")
14  django/contrib/staticfiles/storage.py
@@ -32,13 +32,21 @@ def __init__(self, location=None, base_url=None, *args, **kwargs):
32 32
             location = settings.STATIC_ROOT
33 33
         if base_url is None:
34 34
             base_url = settings.STATIC_URL
  35
+        check_settings(base_url)
  36
+        super(StaticFilesStorage, self).__init__(location, base_url,
  37
+                                                 *args, **kwargs)
  38
+        # FileSystemStorage fallbacks to MEDIA_ROOT when location
  39
+        # is empty, so we restore the empty value.
35 40
         if not location:
  41
+            self.base_location = None
  42
+            self.location = None
  43
+
  44
+    def path(self, name):
  45
+        if not self.location:
36 46
             raise ImproperlyConfigured("You're using the staticfiles app "
37 47
                                        "without having set the STATIC_ROOT "
38 48
                                        "setting to a filesystem path.")
39  
-        check_settings(base_url)
40  
-        super(StaticFilesStorage, self).__init__(location, base_url,
41  
-                                                 *args, **kwargs)
  49
+        return super(StaticFilesStorage, self).path(name)
42 50
 
43 51
 
44 52
 class CachedFilesMixin(object):

0 notes on commit 6728f15

Please sign in to comment.
Something went wrong with that request. Please try again.