Opened 3 years ago

Closed 3 years ago

#33494 closed Bug (invalid)

Collectstatic fails with Django 4 and SourcemapManifestStaticFilesStorage

Reported by: Felix Kleinekathöfer Owned by: nobody
Component: contrib.staticfiles Version: 4.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Felix Kleinekathöfer)

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

Change History (3)

comment:1 by Felix Kleinekathöfer, 3 years ago

Description: modified (diff)

comment:2 by Felix Kleinekathöfer, 3 years ago

Description: modified (diff)

comment:3 by Felix Kleinekathöfer, 3 years ago

Resolution: invalid
Status: newclosed

My bad. We are overriding some code.

Note: See TracTickets for help on using tickets.
Back to Top