reverse URL resolution triggers import errors on views
|Reported by:||kcarnold||Owned by:||nobody|
|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|
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.