Changes between Version 11 and Version 13 of Ticket #33353


Ignore:
Timestamp:
Jan 6, 2022, 9:21:18 AM (3 years ago)
Author:
Adam Johnson
Comment:

Could we please at least add a settings options to allow one to disable this new behaviour that breaks quite a few packages?

The assertion "breaks quite a few packages" is not sustained by the evidence of *one* package. IMO there's still not enough evidence to revert.

The package in question isn't tested with Django 3.2 nor 4.0. Try helping there!

You're right that you can revert the behaviour for your project by defining your own static files storage with the pattern removed. I was just writing this version before your comment came in:

from django.contrib.staticfiles.storage import ManifestStaticFilesStorage


class NoSourceMapsStorage(ManifestStaticFilesStorage):
    patterns = (
        (
            "*.css",
            (
                "(?P<matched>url\\(['\"]{0,1}\\s*(?P<url>.*?)[\"']{0,1}\\))",
                (
                    "(?P<matched>@import\\s*[\"']\\s*(?P<url>.*?)[\"'])",
                    '@import url("%(url)s")',
                ),
            ),
        ),
    )

Don't forget to set STATICFILES_STORAGE to point to your custom storage class.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #33353 – Description

    v11 v13  
    1 Some django packages include JavaScript files, but not the sourcemaps, e.g. `django-json-widget` see: https://github.com/jmrivas86/django-json-widget/issues/63
     1If one is using 3rd party JavaScript library, its often a minified Javascript file, that quite likely it has a source map url in a comment at the end. However its very likely that one does not have this source map files for the vendor libraries (probably only the vendor uses them).
    22
    3 Django version 4 introduces a new features of adjusting the URLs of these source map urls. Unfortunately if one does not have these source maps, its generates an error and stops. This seems unncessary that one can't create a release in production due to an unused third party file.
     3Django version 4 introduces a new features of adjusting the URLs of these source map urls. Unfortunately if one does not have these source maps, its generates an error and stops. This seems unncessary that one can't create a release due to an unused third party file.
    44
    5 Although I think it should only print a warning, as dicussed below people feel its worthwhile to keep this breaking change. Could we please least makie it only raise an error if `settings.DEBUG == True`? That way in production where the sourcemaps are used less, its okay.
     5During storage post processes the files, if it can't file the file in the URL, please rather print a warning, or just skip replacing that url.
    66
    7 Alternatively/Additionally, could there be a `settings.SOURCEMAP_EXCEPTIONS` (or some other name) that allows one to turn off this new behaviour.
     7I would recommend if its a sourcemap, not even printing a warning. For the CSS files it could be worth printing a warning.
Back to Top