[Django] #24243: HashedFilesMixin doesn't handle file name fragments (thus the url template tag neither)

15 views
Skip to first unread message

Django

unread,
Jan 29, 2015, 6:08:53 AM1/29/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+--------------------
Reporter: atleta | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+--------------------
The hashed_name method will raise a ValueError if fed a non-existent file
(including a file name fragment) which problematic for several reasons:
* File name fragments can't be used this way (e.g. I want to do {% url
'/static/sounds/some_sound' %} and then append the extension from
javascript)
* The above technique works with cache middle ware not using
HashedFilesMixin, so the ValueError comes kind of unexpected (e.g. when
only using it on staging/deployment environments and not locally)
* Actually just below the offending code it explicitly tries to handle
fragments, even has a comment about it, but the exception is raised
before.

Problematic code starts on line 89.

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

Django

unread,
Jan 29, 2015, 6:09:47 AM1/29/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner: atleta
Type: Uncategorized | Status: assigned
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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


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

Django

unread,
Jan 29, 2015, 6:16:59 AM1/29/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner:

Type: Uncategorized | Status: new
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* status: assigned => new
* owner: atleta =>


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

Django

unread,
Jan 29, 2015, 7:14:59 AM1/29/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner:

Type: Uncategorized | Status: new
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by atleta):

After looking into it, now I see that I misunderstood the word 'fragment'
in the comments and it refers to url fragments, not file name fragments
(as in partial file names). However, what I have described above is still
a valid behaviour and in line with the default
django.contrib.staticfiles.storage.StaticFilesStorage behaviour.

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

Django

unread,
Jan 29, 2015, 7:15:14 AM1/29/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner: atleta
Type: Uncategorized | Status: assigned
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* owner: => atleta


* status: new => assigned


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

Django

unread,
Mar 3, 2015, 3:23:35 PM3/3/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner: atleta
Type: Uncategorized | Status: assigned
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* easy: 1 => 0


Comment:

Can you offer a patch for this issue? I'm having trouble understanding
exactly what changes you're proposing to make?

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

Django

unread,
Mar 5, 2015, 6:11:35 AM3/5/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner: atleta
Type: Uncategorized | Status: closed
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

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


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

Django

unread,
Mar 5, 2015, 8:31:10 AM3/5/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner: atleta
Type: Uncategorized | Status: closed
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by atleta):

The change I'm suggesting is that resolving a non-existent file name
doesn't raise a ValueError when using ManifestStaticFilesStorage (change
needed in HashedFilesMixin). Though it was 5 weeks ago, it seems I have
done the fix back then.

Do I attach a file containing the suggested fix here or do I create a pull
request? (The documentation wasn't 100% clear.)

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

Django

unread,
Mar 5, 2015, 8:45:43 AM3/5/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner: atleta
Type: Uncategorized | Status: closed
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

Pull requests are preferred. Let me know which documentation you were
confused by so we can update it.

--
Ticket URL: <https://code.djangoproject.com/ticket/24243#comment:8>

Django

unread,
Mar 5, 2015, 9:59:35 AM3/5/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner: atleta
Type: Uncategorized | Status: closed
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by atleta):

Pull request created. Can't remember the documentation that caused the
confusion, it was over a month ago. Will let you know if I see it again.

--
Ticket URL: <https://code.djangoproject.com/ticket/24243#comment:9>

Django

unread,
Mar 5, 2015, 10:39:32 AM3/5/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner: atleta
Type: Uncategorized | Status: closed
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aaugustin):

Isn't this a duplicate of #18958?

--
Ticket URL: <https://code.djangoproject.com/ticket/24243#comment:10>

Django

unread,
Mar 5, 2015, 10:57:16 AM3/5/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner: atleta
Type: Uncategorized | Status: closed
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by atleta):

Nope, it isn't. What I'm doing is being able to use

{{{
{% static 'wherever/some/of/your/files/are/' %}
}}}

or e.g. (generated js)
{{{
var sound = '{% static 'sounds/mysound' %}';
}}}

and then append .mp3 or .ogg depending on the browser capabilities. Both
files are present. Actually #18958 would still be an issue for the
reporter after accepting my patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/24243#comment:11>

Django

unread,
Mar 6, 2015, 6:30:01 AM3/6/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner: atleta
Type: New feature | Status: new
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: closed => new
* type: Uncategorized => New feature
* resolution: needsinfo =>


Comment:

Reopening for further consideration.

--
Ticket URL: <https://code.djangoproject.com/ticket/24243#comment:12>

Django

unread,
Mar 7, 2015, 4:33:31 AM3/7/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner: atleta
Type: New feature | Status: new
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aaugustin):

With the example above, `var sound = '{% static 'sounds/mysound' %}';`
should be rendered as `var sound = '/static/sounds/mysound.e678b76a';`.
How does Django determine the hash to insert there?

--
Ticket URL: <https://code.djangoproject.com/ticket/24243#comment:13>

Django

unread,
Mar 12, 2015, 11:35:41 AM3/12/15
to django-...@googlegroups.com
#24243: HashedFilesMixin doesn't handle file name fragments (thus the url template
tag neither)
-------------------------------------+-------------------------------------
Reporter: atleta | Owner: atleta
Type: New feature | Status: new
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by atleta):

It does not. In this case, cache busting doesn't work.

--
Ticket URL: <https://code.djangoproject.com/ticket/24243#comment:14>

Django

unread,
Mar 26, 2015, 8:10:34 PM3/26/15
to django-...@googlegroups.com
#24243: Allow HashedFilesMixin to handle file name fragments
-------------------------------------+------------------------------------
Reporter: atleta | Owner: atleta
Type: New feature | Status: new
Component: contrib.staticfiles | Version: master
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 timgraham):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* version: 1.7 => master
* stage: Unreviewed => Accepted


Comment:

I'm tentatively accepting this ticket, although I'd like to confirm with
@jezdez who authored `HashedFilesMixin`.

As far as I could tell when using it (I tested with
`CachedStaticFilesStorage`), `{% static 'foo/bar' %}` (that doesn't exist)
will only cause an error when `DEBUG=False` (without this patch). This
doesn't seem like a great behavior (errors go undetected until you're
running in production). A better behavior might be log a warning when
`DEBUG=True`. With this patch, references to missing files go undetected,
but at least won't get crashes in production for missing files.

--
Ticket URL: <https://code.djangoproject.com/ticket/24243#comment:15>

Django

unread,
Feb 25, 2016, 10:02:49 PM2/25/16
to django-...@googlegroups.com
#24243: Allow HashedFilesMixin to handle file name fragments
-------------------------------------+------------------------------------
Reporter: atleta | Owner: atleta
Type: New feature | Status: new
Component: contrib.staticfiles | Version: master
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 edwardotis):

Hi all,

What happened to this bug? It's killing my deployment to production on
Heroku with DEBUG=False. Raising an uncaught ValueError in post_process
that kills collectstatic and breaks deployments is a sub optimal design
decision.

A single missing static file blocks my entire production deployment for
Django 1.7 - 1.9

I should be able to override this behavior with something like an optional
--no-strict flag on collectstatic.
The default could be strict (as it is today), and then developers like me
could make the choice to get our deployment out to production with a
missing file, instead of being completely (and surprisingly) blocked.

What are the steps to re-open this?

--
Ticket URL: <https://code.djangoproject.com/ticket/24243#comment:16>

Django

unread,
Feb 26, 2016, 7:17:13 AM2/26/16
to django-...@googlegroups.com
#24243: Allow HashedFilesMixin to handle file name fragments
-------------------------------------+------------------------------------
Reporter: atleta | Owner: atleta
Type: New feature | Status: new
Component: contrib.staticfiles | Version: master
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 timgraham):

The ticket is open. It's waiting for a patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/24243#comment:17>

Django

unread,
Jul 9, 2021, 6:41:36 AM7/9/21
to django-...@googlegroups.com
#24243: Allow HashedFilesMixin to handle file name fragments
-------------------------------------+-------------------------------------
Reporter: Laszlo Marai | Owner: Laszlo
| Marai
Type: New feature | Status: closed
Component: contrib.staticfiles | Version: dev
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* status: new => closed
* needs_better_patch: 1 => 0
* has_patch: 1 => 0
* resolution: => wontfix
* stage: Accepted => Unreviewed


Comment:

I don't think it's worth the potential confusion and if someone wants to
ignore the missing files they can always use a
`ManifestStaticFilesStorage` subclass (see
[https://github.com/django/django/pull/4246 David's comment]). There is no
need to add this to Django itself.

--
Ticket URL: <https://code.djangoproject.com/ticket/24243#comment:18>

Reply all
Reply to author
Forward
0 new messages