admin_static templatetag is not using the staticfiles' storage
|Reported by:||generalov||Owned by:||aaugustin|
|Severity:||Release blocker||Keywords:||admin_static admin app-loading|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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 12 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
comment:4 Changed 12 months ago by Aymeric Augustin <aymeric.augustin@…>
- Resolution set to fixed
- Status changed from assigned to closed