Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#22939 closed Bug (fixed)

admin_static templatetag is not using the staticfiles' storage

Reported by: generalov Owned by: aaugustin
Component: Core (Other) Version: 1.7-rc-1
Severity: Release blocker Keywords: admin_static admin app-loading
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I set STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage' but I noted what admin pages still contains not hashed urls for static.

It's looks like the static templatetag from django/contrib/admin/templatetags/admin_static.py is not uses the staticfiles' storage. It seems there is a bug in the implementation.

The condition if apps.is_installed('django.contrib.staticfiles'): at https://github.com/django/django/blob/master/django/contrib/admin/templatetags/admin_static.py#L6
is always False and staticfiles backend is nether used.

The implementation of is_installed method https://github.com/django/django/blob/master/django/apps/registry.py#L205
looks up the application in the self.app_configs. This array is populated consecutively by self.populate method from settings.INSTALLED_APPS.

The default [INSTALLED_APPS](https://github.com/django/django/blob/master/django/conf/project_template/project_name/settings.py#L32) is:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

The 'django.contrib.auth' is stays before 'django.contrib.staticfiles'. Therefore when, config for 'django.contrib.auth' is populated, then django.contrib.staticfiles is not configured yet and it is absend in the self.app_configs. Therefore apps.is_installed('django.contrib.staticfiles') returns False.

The current solution is put django.config.staticfiles before django.confib.auth in the INSTALLED_APPS. But it seems the bug in the logic of method Apps.is_installed because it checks not for application is installed but for application is configured.

Change History (5)

comment:1 Changed 14 months ago by aaugustin

  • Component changed from Uncategorized to Core (Other)
  • Keywords app-loading added
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to aaugustin
  • Patch needs improvement unset
  • Severity changed from Normal to Release blocker
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug

There's no difference between "installing" and "configuring" an app.

Until you've processed all entries in INSTALLED_APPS, you haven't resolved all AppConfig.name values so you don't know which apps are installed.

I think we need to reintroduce a flag to tell whether the first phase of the app registry population process is complete and have is_installed raise an error if that flag isn't set.

In addition, we need to defer the check in admin_static.py or at least make sure it doesn't get imported too early.

comment:4 Changed 14 months ago by Aymeric Augustin <aymeric.augustin@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 22b2fb0ba1d130c0ff0e1658ee9c2224a619a4a7:

Fixed #22939 -- Delayed admin_static backend detection

Thanks generalov for the report.

comment:5 Changed 14 months ago by Aymeric Augustin <aymeric.augustin@…>

In be38c5bcc8b6d641d210cbcf0508605223366778:

[1.7.x] Fixed #22939 -- Delayed admin_static backend detection

Thanks generalov for the report.

Backport of 22b2fb0b from master

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