Django: Ticket #6333: urlresolvers.resolve barfs on regexps with a flag grouphttps://code.djangoproject.com/ticket/6333
<p>
I think I've just run across a small bug with the reverse() method in urlresolvers.py for URLs that contain a flag group (like (?u)). To replicate, construct a urlconf containing a regexp with a flag group, e.g.
</p>
<div class="code"><pre> url<span class="p">(</span><span class="s">r'(?u)^foo/(?P&lt;id&gt;\d+)/$'</span><span class="p">,</span> name<span class="o">=</span><span class="s">'foo-url'</span><span class="p">)</span>
</pre></div><p>
and then use django.core.urlresolvers.reverse to construct a url with parameters:
</p>
<div class="code"><pre> reverse<span class="p">(</span><span class="s">'foo-url'</span><span class="p">,</span> kwargs<span class="o">=</span><span class="nb">dict</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="mi">12</span><span class="p">))</span>
</pre></div><p>
I get a NoMatchError here (not enough positional arguments), but I don't if I remove the flag group at the beginning of the url regexp.
</p>
<p>
I've attached a small patch for this issue ; the Python re docs state that a flag group should be the first non-whitespace content in the regexp, so I only cover that case.
</p>
en-usDjangohttps://www.djangoproject.com/s/img/site/hdr_logo.gifhttps://code.djangoproject.com/ticket/6333
Trac 1.0.4leif@…Mon, 07 Jan 2008 00:25:54 GMTattachment sethttps://code.djangoproject.com/ticket/6333
https://code.djangoproject.com/ticket/6333
<ul>
<li><strong>attachment</strong>
set to <em>django-regexp-flags.diff</em>
</li>
</ul>
Ticketleif@…Mon, 07 Jan 2008 00:30:09 GMTneeds_docs, needs_tests, needs_better_patch sethttps://code.djangoproject.com/ticket/6333#comment:1
https://code.djangoproject.com/ticket/6333#comment:1
<ul>
<li><strong>needs_docs</strong>
unset
</li>
<li><strong>needs_tests</strong>
unset
</li>
<li><strong>needs_better_patch</strong>
unset
</li>
</ul>
<p>
Sorry, I just re-read the Python re docs and I realized only the x flag has to be at the beginning of the regexp. I've updated the patch to ignore all flag groups in the url regexp.
</p>
Ticketleif@…Mon, 07 Jan 2008 00:30:53 GMTattachment sethttps://code.djangoproject.com/ticket/6333
https://code.djangoproject.com/ticket/6333
<ul>
<li><strong>attachment</strong>
set to <em>django-regexp-flags.2.diff</em>
</li>
</ul>
TicketSimon Greenhill <dev@…>Sun, 13 Jan 2008 12:30:35 GMTstage changedhttps://code.djangoproject.com/ticket/6333#comment:2
https://code.djangoproject.com/ticket/6333#comment:2
<ul>
<li><strong>stage</strong>
changed from <em>Unreviewed</em> to <em>Ready for checkin</em>
</li>
</ul>
TicketmtredinnickSun, 03 Feb 2008 09:14:23 GMTstatus changed; resolution sethttps://code.djangoproject.com/ticket/6333#comment:3
https://code.djangoproject.com/ticket/6333#comment:3
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>wontfix</em>
</li>
</ul>
<p>
Not worth fixing quite like this. Firstly, in this particular case, you don't need the "u" flag, since all of those matches are done with <tt>re.UNICODE</tt> being used. Secondly, a rewrite of that portion of the code is in progress that fixes things a bit more holistically.
</p>
Ticket