#36562: `StaticFilesStorage` should respect `base_url` and treat `STATIC_URL` 
as a
fallback
-------------------------------------+-------------------------------------
     Reporter:  Kamil Paduszyński    |                    Owner:  (none)
         Type:  Bug                  |                   Status:  closed
    Component:  contrib.staticfiles  |                  Version:  5.2
     Severity:  Normal               |               Resolution:
                                     |  worksforme
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

 * resolution:   => worksforme
 * status:  new => closed
 * type:  Uncategorized => Bug

Comment:

 Hello Kamil Paduszyński, thank you for taking the time to create this
 ticket.

 I invested some time investigating this, and I can't reproduce the error
 you shared. I tried various local settings and they all work. So then, I
 wrote a test that shows how the `base_url` from `OPTIONS` gets used by the
 `StaticFilesStorage`. This test is passing in `main`:

 {{{#!diff
 diff --git a/tests/staticfiles_tests/test_checks.py
 b/tests/staticfiles_tests/test_checks.py
 index b9ac486ed1..9243546eef 100644
 --- a/tests/staticfiles_tests/test_checks.py
 +++ b/tests/staticfiles_tests/test_checks.py
 @@ -164,3 +164,22 @@ class StoragesCheckTests(SimpleTestCase):
      def test_staticfiles_no_errors(self):
          errors = check_storages(None)
          self.assertEqual(errors, [])
 +
 +    @override_settings(
 +        STATIC_URL=None,
 +        STORAGES={
 +            "staticfiles": {
 +                "BACKEND":
 "django.contrib.staticfiles.storage.StaticFilesStorage",
 +                "OPTIONS": {"base_url": "override/"},
 +            }
 +        },
 +    )
 +    def test_base_url_in_storages_options_without_static_url(self):
 +        """
 +        Providing base_url in STORAGES['staticfiles']['OPTIONS'] should
 be
 +        sufficient to configure StaticFilesStorage without STATIC_URL.
 +        Currently it still raises ImproperlyConfigured.
 +        """
 +        from django.core.files.storage import storages
 +        storage = storages["staticfiles"]
 +        self.assertEqual(storage.base_url, "override/")
 }}}

 Because of the above, I'll close as `worksforme`. If you still have this
 issue, before re-opening please be sure to provide a failing test case for
 the Django test suite or provide a minimal Django test project for us to
 reproduce.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36562#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070198c36367f9-4a22d8f9-2e74-4751-859d-e35bb9940f88-000000%40eu-central-1.amazonses.com.

Reply via email to