Code

Opened 6 years ago

Closed 6 years ago

Last modified 2 years ago

#9123 closed Uncategorized (invalid)

URL Resolver tag chokes with verbose regex in the urlconf

Reported by: programmerq Owned by: nobody
Component: Template system Version: 1.0
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

Any project that uses python verbose regular expressions in its urlconf causes the {% url %} tag to crash. I believe that the culprit is likely r8760, though I haven't tested that theory. The {% url %} tag throws a TemplateSyntaxError with Exception Value: Caught an exception while rendering: Non-reversible reg-exp portion: '(?x'

If r8760 really was the culprit, then it isn't 100% backwards compatible.

Attachments (0)

Change History (3)

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

Backwards-compatible doesn't mean that it necessarily continues to work for things it wasn't originally designed for that just happened to work by accident. It's unfortunate that there were some of these accidental cases that people were relying on, but there's nothing that can be done about that.

The reverse resolver does explicitly exclude (?x) and raises an appropriately descriptive error message. It initially appeared to complicate the code too much to handle that, but if you want to write a patch that isn't too intrusive, it would certainly be nice to include it.

Closing this for now, since the reverse resolver works as expected. If you do write a patch, please, by all means, open a new ticket and attach it.

comment:2 Changed 6 years ago by programmerq

The problem isn't necessarily that the reverse mapper can't generate a reverse for a verbose regex, as much as it breaks *all* url tags.

When I went to the admin main page, it'd die and throw the error from the admin template. This made debugging the actual underlying issue very cryptic and strange.

I was playing with the old URL resolver, and it appears that it can't exactly "figure out" a url based on a verbose regex, but it wouldn't choke and die if there happened to be a verbose regex in the urlconf.

I'll try to at least work out a different way to "die better" and open a new ticket with that patch. It really made quite the head scratcher for me and a couple people that had no idea why in the world the admin app appeared to not be working once upgrading to 1.0.

comment:3 Changed 2 years ago by gregplaysguitar

  • Easy pickings unset
  • Severity set to Normal
  • Type set to Uncategorized
  • UI/UX unset

As of django 1.3, this is still an issue. There is no reason why one non-reversible url should break the entire url tag, and no mention in the docs that it does this.

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.