Opened 11 years ago

Closed 11 years ago

#22805 closed Cleanup/optimization (wontfix)

urlresolvers.get_callable() need to present the inner exception if any

Reported by: fangsboyfriend@… Owned by: nobody
Component: Core (Other) Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When I start a django project with command 'manage.py runserver'

I got the following exception; I feel so puzzled about it. In fact, the view really exist. Why it say no?

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 101, i
n get_response
    request.path_info)
  File "C:\Python27\lib\site-packages\django\core\urlresolvers.py", line 303, in
 resolve
    sub_match = pattern.resolve(new_path)
  File "C:\Python27\lib\site-packages\django\core\urlresolvers.py", line 212, in
 resolve
    return ResolverMatch(self.callback, args, kwargs, self.name)
  File "C:\Python27\lib\site-packages\django\core\urlresolvers.py", line 219, in
 callback
    self._callback = get_callable(self._callback_str)
  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 27, in w
rapper
    result = func(*args)
  File "C:\Python27\lib\site-packages\django\core\urlresolvers.py", line 104, in
 get_callable
    (lookup_view, mod_name))
ViewDoesNotExist: Could not import desktop.desktop_views.portal. View does not exist in module desktop.desktop_views.

After reading the source code [line 101, urlresolvers.py], I found that the root reason is the 'AttributeError'.

except AttributeError:
            if not can_fail:
                raise ViewDoesNotExist(
                    "Could not import %s. View does not exist in module %s." %
                    (lookup_view, mod_name))

So I suggest to add the details of AttributeError within the final ViewDoesNotExist exception. It would make the diagnosis more easier.

Change History (4)

comment:2 by mardini, 11 years ago

I personally don't think the exception message (ViewDoesNotExist: Could not import ... View does not exist in module ...) is ambiguous. In fact, that particular exception is used to make the error more clear. What info from AttributeError did you find would make the error message better?

in reply to:  2 comment:3 by Jacky, 11 years ago

Replying to mardini:

I personally don't think the exception message (ViewDoesNotExist: Could not import ... View does not exist in module ...) is ambiguous. In fact, that particular exception is used to make the error more clear. What info from AttributeError did you find would make the error message better?

*
The call stack of AttributeError make it much more easier to find out the root cause(It tells where the first exception raised). Also, ViewDoesNotExist misleads me since the view does exist.

The root reason why ViewDoesNotExist raised is due to the AttributeError, and this is happened during importing the view. It would be make more sense to renaming 'ViewDoesNotExist' to 'LoadViewFailedError' and presenting the details of the inner exception (To give sufficient info about the error for diagnosis).

comment:4 by Tim Graham, 11 years ago

Resolution: wontfix
Status: newclosed

Actually, we are likely to deprecate using strings as views in urlpatterns, partially for this reason. See #22384, for example. I think our efforts are better spent doing that, but thanks for raising the issue.

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