Opened 16 years ago
Last modified 15 years ago
#8764 closed
Mixing args and **kwargs in reverse() function — at Version 1
Reported by: | Adrian Ribao | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Keywords: | reverse function exception | |
Cc: | aribao@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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.
(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.