Opened 4 years ago

Closed 13 months ago

#15723 closed Cleanup/optimization (needsinfo)

Document limitations of reverse

Reported by: zeroos Owned by: nobody
Component: Documentation Version: master
Severity: Normal Keywords: reverse regexp
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In urls.py I have the following line:

...
(r'^json/calendar/((?P<course>[\d,]+)/)?$', json.calendar_block),
...

When I try to reverse this url this way:

reverse(json.calendar_block, kwargs={'course': 1})

I get an error saying that it cannot reverse this.

When I change the line in urls.py to:

...
(r'^json/calendar/(?P<course>[\d,]+)/$', json.calendar_block),
...

everything works great.

I would assume that it is not a bug, but it worked before and suddenly, after pulling the newest Django release from svn it stopped.

Change History (7)

comment:1 Changed 4 years ago by lukeplant

  • Type set to Bug

comment:2 Changed 4 years ago by lukeplant

  • Severity set to Normal

comment:3 Changed 4 years ago by julien

  • Component changed from Core (Other) to Documentation
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Bug to Cleanup/optimization

The reverse() function does have some limitations, as stated in the doc (http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse): "The reverse() function can reverse a large variety of regular expression patterns for URLs, but not every possible one". I think this is the case here. The documentation can be improved though, to reflect all (or at least the most common) limitations.

comment:4 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:5 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:6 Changed 3 years ago by timo

  • Summary changed from reverse does not work if quotation mark is used on a keyword argument to Document limitations of reverse

I am not sure what to add here as far as docs go. The code for reverse doesn't look too simple to me, and I am not sure how much detail we want to go into about how it works. Maybe the fact that nested groupings aren't supported? I haven't confirmed that to be the case, it's just a guess based on the example that doesn't work.

comment:7 Changed 13 months ago by timo

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

In the doc we have: "The main restriction at the moment is that the pattern cannot contain alternative choices using the vertical bar ("|") character." I am closing this as needsinfo. If someone wants to do research and propose a patch, then please reopen with details.

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