Code

Opened 2 years ago

Closed 2 years ago

#17689 closed Bug (fixed)

CachedFilesMixin causes ValueError when provided with a path to url()

Reported by: tkaemming Owned by: nobody
Component: contrib.staticfiles Version: 1.4-alpha-1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

For example, trying to set window.__admin_media_prefix__ in admin/base.html causes this error.

Here's the offending template tag:
https://code.djangoproject.com/browser/django/trunk/django/contrib/admin/templates/admin/base.html#L9

Traceback (I cut out the render bits and only left the parts significant to the issue at hand):

[pid: 23479|app: 0|req: 2/11] 127.0.0.1 () {40 vars in 780 bytes} [Tue Feb 14 19:42:53 2012] GET /admin/ => generated 168 bytes in 430 msecs (HTTP/1.0 500) 4 headers in 174 bytes (1 switches on core 0)
Internal Server Error: /admin/
Traceback (most recent call last):
  File "/srv/versions/development/src/django/django/contrib/staticfiles/templatetags/staticfiles.py", line 13, in static
    return staticfiles_storage.url(path)
  File "/srv/versions/development/src/django/django/contrib/staticfiles/storage.py", line 111, in url
    hashed_name = self.hashed_name(clean_name).replace('\\', '/')
  File "/srv/versions/development/src/django/django/contrib/staticfiles/storage.py", line 74, in hashed_name
    (clean_name, self))
ValueError: The file 'admin/' could not be found with <example.utils.storage.CachedS3BotoStorage object at 0x8ce99cc>.

I've attached a patch that prevents CachedStaticMixin from attempting to hash names ending in a path separator (forward slash only), incl. tests.

Attachments (1)

ticket-17689.diff (2.2 KB) - added by tkaemming 2 years ago.

Download all attachments as: .zip

Change History (3)

Changed 2 years ago by tkaemming

comment:1 Changed 2 years ago by tkaemming

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.3 to 1.4-alpha-1

comment:2 Changed 2 years ago by jezdez

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

In [17535]:

Fixed #17689 -- Stopped the CachedStaticFilesStorage from trying to hash paths that aren't files.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.