[Django] #33494: Collectstatic fails with Django 4 and SourcemapManifestStaticFilesStorage

2 views
Skip to first unread message

Django

unread,
Feb 5, 2022, 8:35:20 AM2/5/22
to django-...@googlegroups.com
#33494: Collectstatic fails with Django 4 and SourcemapManifestStaticFilesStorage
------------------------------------------------+------------------------
Reporter: Felix Kleinekathöfer | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
I've tried updating a django app to 4.0. We are building our scripts with
gulp which are then collected by
Django. Here is an example script asset which is being picked up:

{{{
"use strict";

(function () {
// Automatically check "Uploaded avatar" radio button if user selects an
avatar.
Array.prototype.forEach.call(document.querySelectorAll('.avatar-image-
upload'), function (el) {
var form = el.closest('form');
var radioButton =
form.querySelector('input[type=radio][name=avatar_from][value=upload]');
el.addEventListener('change', function () {
if (el.value === '') return;
radioButton.checked = true;
});
});
})();

//# sourceMappingURL=../../../../maps/spongeauth/static/scripts/app.js.map
}}}

This file worked well with Django 3 but now it ends up in a KeyError:

{{{
app_1 | + /home/spongeauth/env/bin/python spongeauth/manage.py
collectstatic --noinput
app_1 | Traceback (most recent call last):
app_1 | File "/home/spongeauth/app/spongeauth/manage.py", line 28, in
<module>
app_1 | execute_from_command_line(sys.argv)
app_1 | File "/home/spongeauth/env/lib/python3.10/site-
packages/django/core/management/__init__.py", line 425, in
execute_from_command_line
app_1 | utility.execute()
app_1 | File "/home/spongeauth/env/lib/python3.10/site-
packages/django/core/management/__init__.py", line 419, in execute
app_1 | self.fetch_command(subcommand).run_from_argv(self.argv)
app_1 | File "/home/spongeauth/env/lib/python3.10/site-
packages/django/core/management/base.py", line 373, in run_from_argv
app_1 | self.execute(*args, **cmd_options)
app_1 | File "/home/spongeauth/env/lib/python3.10/site-
packages/django/core/management/base.py", line 417, in execute
app_1 | output = self.handle(*args, **options)
app_1 | File "/home/spongeauth/env/lib/python3.10/site-
packages/django/contrib/staticfiles/management/commands/collectstatic.py",
line 187, in handle
app_1 | collected = self.collect()
app_1 | File "/home/spongeauth/env/lib/python3.10/site-
packages/django/contrib/staticfiles/management/commands/collectstatic.py",
line 128, in collect
app_1 | for original_path, processed_path, processed in processor:
app_1 | File "/home/spongeauth/env/lib/python3.10/site-
packages/django/contrib/staticfiles/storage.py", line 426, in post_process
app_1 | yield from super().post_process(*args, **kwargs)
app_1 | File "/home/spongeauth/env/lib/python3.10/site-
packages/django/contrib/staticfiles/storage.py", line 247, in post_process
app_1 | for name, hashed_name, processed, _ in
self._post_process(paths, adjustable_paths, hashed_files):
app_1 | File "/home/spongeauth/env/lib/python3.10/site-
packages/django/contrib/staticfiles/storage.py", line 312, in
_post_process
app_1 | content = pattern.sub(converter, content)
app_1 | File "/home/spongeauth/env/lib/python3.10/site-
packages/django/contrib/staticfiles/storage.py", line 173, in converter
app_1 | matched = matches['matched']
app_1 | KeyError: 'matched'
}}}

I can't find a note on the migration docs that sourceFileMappingURLs need
to be changed, so I suspect this being a bug.

Source: https://github.com/SpongePowered/SpongeAuth/pull/926

--
Ticket URL: <https://code.djangoproject.com/ticket/33494>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 5, 2022, 8:56:43 AM2/5/22
to django-...@googlegroups.com
#33494: Collectstatic fails with Django 4 and SourcemapManifestStaticFilesStorage
-------------------------------------+-------------------------------------
Reporter: Felix | Owner: nobody
Kleinekathöfer |

Type: Bug | Status: new
Component: contrib.staticfiles | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Felix Kleinekathöfer:

Old description:

New description:

{{{
"use strict";

//# sourceMappingURL=../../../../maps/spongeauth/static/scripts/app.js.map
}}}

I think this RegEx is the problem:
https://github.com/django/django/blob/main/django/contrib/staticfiles/storage.py#L61.
The "matched" group matches nothing. It should be something like
{{{
(?m)(?P<matched>[\s\S]*)^(//# (?-i:sourceMappingURL)=(?P<url>.*))$
}}}
maybe. I also do not see any sourceMappingURL support for css. Has it been
removed?


Source: https://github.com/SpongePowered/SpongeAuth/pull/926

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33494#comment:1>

Django

unread,
Feb 5, 2022, 9:25:57 AM2/5/22
to django-...@googlegroups.com
#33494: Collectstatic fails with Django 4 and SourcemapManifestStaticFilesStorage
-------------------------------------+-------------------------------------
Reporter: Felix | Owner: nobody
Kleinekathöfer |
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Felix Kleinekathöfer:

Old description:

> I've tried updating a django app to 4.0. We are building our scripts with

> I think this RegEx is the problem:
> https://github.com/django/django/blob/main/django/contrib/staticfiles/storage.py#L61.
> The "matched" group matches nothing. It should be something like
> {{{
> (?m)(?P<matched>[\s\S]*)^(//# (?-i:sourceMappingURL)=(?P<url>.*))$
> }}}
> maybe. I also do not see any sourceMappingURL support for css. Has it
> been removed?
>

> Source: https://github.com/SpongePowered/SpongeAuth/pull/926

New description:

{{{
"use strict";

//# sourceMappingURL=../../../../maps/spongeauth/static/scripts/app.js.map
}}}

I think this RegEx is the problem:

I also do not see any sourceMappingURL support for css. Has it been
removed or was it never a feature?


Source: https://github.com/SpongePowered/SpongeAuth/pull/926

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33494#comment:2>

Django

unread,
Feb 5, 2022, 9:56:31 AM2/5/22
to django-...@googlegroups.com
#33494: Collectstatic fails with Django 4 and SourcemapManifestStaticFilesStorage
-------------------------------------+-------------------------------------
Reporter: Felix | Owner: nobody
Kleinekathöfer |
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 4.0
Severity: Normal | Resolution: invalid

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 Felix Kleinekathöfer):

* status: new => closed
* resolution: => invalid


Comment:

My bad. We are overriding some code.

--
Ticket URL: <https://code.djangoproject.com/ticket/33494#comment:3>

Reply all
Reply to author
Forward
0 new messages