#8764: Mixing args and **kwargs in reverse() function
-------------------------------------+--------------------------------------
Reporter: tolano | Owner: nobody
Status: new | Milestone:
Component: Core framework | Version: SVN
Resolution: | Keywords: reverse function
exception
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
-------------------------------------+--------------------------------------
Changes (by mtredinnick):
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* milestone: 1.0 =>
Old description:
> Changeset [8760] introduced this exception: "Don't mix *args and
> **kwargs in call to reverse()!"
>
> {{{
> django/trunk/django/core/urlresolvers.py
> def reverse(self, lookup_view, *args, **kwargs):
> if args and kwargs:
> raise ValueError("Don't mix *args and **kwargs in call to
> reverse()!")
> }}}
>
> [8760] was suppose to be backwards compatible but is not. My question is:
> Why is not possible to mis args and kwargs? I don't understand the
> reason, and all of my reverse funcions will fail because of this.
>
> I'll write an example of the problem. All my urls are prepared
> following the best SEO rules, so in many places I have urls like:
> (r'^(.*)-f(?P<id>\d+)\.html$','view_photo')
>
> this would make the url:
> my-photo-f2.html
>
> I get the url using:
>
> {{{
> reverse('app.views.view_photo', args=[slugify(photo.title)],
> kwargs={'id':id})
> }}}
> (Note: I don't want to use a slug field.)
>
> Now this won't work. Well, IMHO this is a bug. I don't see any reason why
> the reverse function shouldn't work the same way as it did before.
> Aplying a patch and make the funcion so limited is not appropiated.
New description:
Changeset [8760] introduced this exception: "Don't mix *args and
**kwargs in call to reverse()!"
{{{
django/trunk/django/core/urlresolvers.py
def reverse(self, lookup_view, *args, **kwargs):
if args and kwargs:
raise ValueError("Don't mix *args and **kwargs in call to
reverse()!")
}}}
[8760] was suppose to be backwards compatible but is not. My question is:
Why is not possible to mis args and kwargs? I don't understand the
reason, and all of my reverse funcions will fail because of this.
I'll write an example of the problem. All my urls are prepared
following the best SEO rules, so in many places I have urls like:
`(r'^(.*)-f(?P<id>\d+)\.html$','view_photo') `
this would make the url:
`my-photo-f2.html`
I get the url using:
{{{
reverse('app.views.view_photo', args=[slugify(photo.title)],
kwargs={'id':id})
}}}
(Note: I don't want to use a slug field.)
Now this won't work. Well, IMHO this is a bug. I don't see any reason why
the reverse function shouldn't work the same way as it did before. Aplying
a patch and make the funcion so limited is not appropiated.
Comment:
(Fixed description formatting)
It's pretty much accidental that that ever worked. There are cases where
mixing positional and keyword arguments will given incorrect results in
the previous code and even more so now (with optional groups). So, ok,
there's an inadvertent backwards incompatibility for something that only
worked by accident. It's simple to work around: pass in either just
positional arguments or just keyword arguments. Both are easy enough to
do.
Somebody will update the BackwardsIncompatibleChanges page at some point
and we can add a docs note. For now, the error message is clear enough
about what needs to be changed in anybody's code that was relying on this.
--
Ticket URL: <http://code.djangoproject.com/ticket/8764#comment:1>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---