[Django] #22353: CachedStaticFilesMixin lags in updating hashed names of other static files referenced in CSS

21 views
Skip to first unread message

Django

unread,
Mar 28, 2014, 3:08:46 PM3/28/14
to django-...@googlegroups.com
#22353: CachedStaticFilesMixin lags in updating hashed names of other static files
referenced in CSS
-------------------------------------+--------------------
Reporter: woodlee | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+--------------------
Procedure to replicate:

1. Be using staticfiles with CachedStaticFilesStorage.
2. Have a CSS file such as 'abc.css' which refers to an image file such as
'xyz.png' (via either "url()" or "@import").
3. Do an initial run of collectstatic. Observe correct substitution of the
path to 'xyz.png' to its hashed name within abc.css.
4. Change the contents of xyz.png (maybe it's a sprites file... so changes
aren't unheard of!).
5. Rerun collectstatic (without the --clear option).
6. Observe that abc.css still refers to the old hashed name of xyz.png;
this is the bug.
7. Run collectstatic a third time.
8. Observe that abc.css now refers to the correct, newer hashed name of
xyz.png.

I believe this is happening because during post_process, when the
url_converter calls url() (see
https://github.com/django/django/blob/1.6.2/django/contrib/staticfiles/storage.py#L195),
url() gets the hashed name out of the staticfiles cache... which has not
yet been updated with the new hashed-name value for the image file, since
said cache updating doesn't happen until the end of post_process.

I think the best solution may be to add a kwarg of 'use_cache=True' to
url(), which url_converter can set to False when it calls url(). When
False, the cache will simply be evaded (not updated) and hashed_name can
be called directly. In this way, url_converter is always substituting to
the most up-to-date hash, but actually updating the cache is still delayed
until the end of post_process, which seems desirable since I think
updating that cache should happen as closely as possible in time to the
moment when the new static assets are placed wherever they'll be served
from (bit of a race condition, there).

Unrelated: it would be nice to warn in documentation that if you define a
separate 'staticfiles' cache in CACHES, it might be desirable to set its
TIMEOUT option to None. I kept wondering why lookups were coming back
empty and eventually realized it was because my staticfiles cache was
using the default 5 minute timeout.

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

Django

unread,
Apr 14, 2014, 6:09:49 PM4/14/14
to django-...@googlegroups.com
#22353: CachedStaticFilesMixin lags in updating hashed names of other static files
referenced in CSS
-------------------------------------+-------------------------------------
Reporter: woodlee | Owner: frog32
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage:
Has patch: 0 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by frog32):

* owner: nobody => frog32
* needs_better_patch: => 0
* status: new => assigned
* needs_tests: => 0
* needs_docs: => 0


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

Django

unread,
Apr 14, 2014, 6:24:10 PM4/14/14
to django-...@googlegroups.com
#22353: CachedStaticFilesMixin lags in updating hashed names of other static files
referenced in CSS
-------------------------------------+-------------------------------------
Reporter: woodlee | Owner: frog32
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage:
Has patch: 0 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0

| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by frog32):

* easy: 1 => 0


Comment:

I am removing the easy pickings because there are more complex problems
involved in this ticket. We need to make sure that in this case the image
is always post-processed before the css file that is referring to it. This
also applies to css files including other css files.

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

Django

unread,
Apr 16, 2014, 10:21:06 AM4/16/14
to django-...@googlegroups.com
#22353: CachedStaticFilesMixin lags in updating hashed names of other static files
referenced in CSS
-------------------------------------+------------------------------------

Reporter: woodlee | Owner: frog32
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by frog32):

* has_patch: 0 => 1
* stage: Unreviewed => Accepted


Comment:

Opened a pull request https://github.com/django/django/pull/2569

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

Django

unread,
Jul 10, 2014, 9:11:38 AM7/10/14
to django-...@googlegroups.com
#22353: CachedStaticFilesMixin lags in updating hashed names of other static files
referenced in CSS
-------------------------------------+------------------------------------
Reporter: woodlee | Owner: frog32
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by timo):

* needs_better_patch: 0 => 1


Comment:

The new test on the PR doesn't pass.

--
Ticket URL: <https://code.djangoproject.com/ticket/22353#comment:4>

Django

unread,
Mar 6, 2015, 8:54:47 AM3/6/15
to django-...@googlegroups.com
#22353: CachedStaticFilesMixin lags in updating hashed names of other static files
referenced in CSS
-------------------------------------+------------------------------------
Reporter: woodlee | Owner: frog32
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by collinanderson):

* cc: cmawebsite@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/22353#comment:5>

Django

unread,
Mar 6, 2015, 9:38:57 AM3/6/15
to django-...@googlegroups.com
#22353: CachedStaticFilesMixin lags in updating hashed names of other static files
referenced in CSS
-------------------------------------+------------------------------------
Reporter: woodlee | Owner: frog32
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by collinanderson):

#24452 is very similar (CSS hash not changing).

--
Ticket URL: <https://code.djangoproject.com/ticket/22353#comment:6>

Django

unread,
Sep 17, 2017, 12:31:27 PM9/17/17
to django-...@googlegroups.com
#22353: CachedStaticFilesMixin lags in updating hashed names of other static files
referenced in CSS
-------------------------------------+-------------------------------------
Reporter: woodlee | Owner: Marc Egli
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 1.6
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ed Morley):

* status: assigned => closed
* resolution: => duplicate


Comment:

This appears to be a dupe of #24452 and friends, and so should be fixed in
Django 1.11.

--
Ticket URL: <https://code.djangoproject.com/ticket/22353#comment:7>

Reply all
Reply to author
Forward
0 new messages