﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33494	Collectstatic fails with Django 4 and SourcemapManifestStaticFilesStorage	Felix Kleinekathöfer	nobody	"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.

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. 

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
"	Bug	closed	contrib.staticfiles	4.0	Normal	invalid			Unreviewed	0	0	0	0	0	0
