Code

Opened 6 years ago

Closed 6 years ago

#6568 closed (wontfix)

reverse URL resolution triggers import errors on views

Reported by: kcarnold 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: UI/UX:

Description

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.

Attachments (0)

Change History (2)

comment:1 Changed 6 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 6 years ago by mtredinnick

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

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.

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.