Code

Opened 4 years ago

Closed 4 years ago

#14715 closed (fixed)

Uninformative ValueError in django/utils/_os.py

Reported by: btubbs Owned by: nobody
Component: Uncategorized Version: 1.3-alpha
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Today I was getting this when trying to run a new project for the first time:

Traceback (most recent call last):
  File "/Users/brent.tubbs/envs/bleeding/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 281, in run
    self.result = application(self.environ, self.start_response)
  File "/Users/brent.tubbs/envs/bleeding/lib/python2.6/site-packages/django/contrib/staticfiles/handlers.py", line 60, in __call__
    response = self.serve(request, self.file_path(environ['PATH_INFO']))
  File "/Users/brent.tubbs/envs/bleeding/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 671, in file_path
    return safe_join(self.media_dir, relative_path)
  File "/Users/brent.tubbs/envs/bleeding/lib/python2.6/site-packages/django/utils/_os.py", line 44, in safe_join
    raise ValueError('the joined path is located outside of the base path'
ValueError: the joined path is located outside of the base path component

I was stumped! I thought maybe it was down to me configuring django.contrib.staticfiles incorrectly. I was wrong. It was because I had set MEDIA_ROOT and/or ADMIN_MEDIA_PREFIX to '', since I'm not using those in my project.

Attaching a patch that makes safe_join give a bit more informative error message to make it easier to debug issues like this. With the patch, you'd get something more like this:

ValueError: the joined path (/) is located outside of the base path component (/Users/brent.tubbs/envs/bleeding/lib/python2.6/site-packages/django/contrib/admin/media)

Attachments (1)

helpful_value_error.patch (638 bytes) - added by btubbs 4 years ago.

Download all attachments as: .zip

Change History (3)

Changed 4 years ago by btubbs

comment:1 Changed 4 years ago by rasca

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Note: the ADMIN_MEDIA_PREFIX check has been fixed in r14593

comment:2 Changed 4 years ago by SmileyChris

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

(In [14699]) Fixes #14715 -- More informative ValueError for safe_join util. Thanks btubbs.

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.