Opened 11 years ago

Closed 11 years ago

#6568 closed (wontfix)

reverse URL resolution triggers import errors on views

Reported by: Kenneth Arnold Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords: reverse url view import error
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Short version: urlresolvers reverse() should check named URLs before trying to import views.

I've gotten bitten by this enough times to convince me it's a bug, and now looking at urlresolvers I'm convinced it's easily fixable.

I use the url template tag and the reverse function all over the place for DRY sake. All of my URLs are named, so there's no reason to look in the views. Not too infrequently I'll make a typo in a view file, causing an import error. That shouldn't bother things when I go to somewhere else on the site that doesn't use that view file. And normally things go just fine... until a page hits a url tag or calls reverse. Then I get an ImportError, because it tried to import the view with a syntax error. The debug page insists that the problem was in the url tag, though, and I have to dig around (usually drop to a shell and try importing each of my views) to find the real cause of the problem.

A simple fix -- and slight optimization -- is to check for lookup_view in reverse_dict before trying to get_callable. I'll write up a patch on Monday if no one else gets to it first.

Change History (2)

comment:1 Changed 11 years ago by Chris Beaven

Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 11 years ago by Malcolm Tredinnick

Resolution: wontfix
Status: newclosed

I think this is symptom hiding, rather than problem fixing. If a views file cannot be imported, that's a bug and isn't something we should be working around. It's something we should be reporting. It's not really a problem that Django doesn't run when given invalid Python code.

Instead of this, we should be fixing the root problem of providing a more comprehensive and appropriate traceback report when view importing fails. That's work in progress.

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