Opened 14 years ago

Closed 14 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: no UI/UX: no

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 14 years ago.

Download all attachments as: .zip

Change History (3)

by btubbs, 14 years ago

Attachment: helpful_value_error.patch added

comment:1 by rasca, 14 years ago

Note: the ADMIN_MEDIA_PREFIX check has been fixed in r14593

comment:2 by Chris Beaven, 14 years ago

Resolution: fixed
Status: newclosed

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

Note: See TracTickets for help on using tickets.
Back to Top