#7957: Chaining Queryset.extra() methods that contain parameters breaks the
query
---------------------------------------+------------------------------------
Reporter: mullendr | Owner: mullendr
Status: reopened | Milestone: 1.0
Component: Database wrapper | Version: SVN
Resolution: | Keywords: queryset extra select
select_params
Stage: Accepted | Has_patch: 1
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------+------------------------------------
Changes (by mtredinnick):
* stage: Unreviewed => Accepted
* milestone: 1.0 beta => 1.0
Old description:
> To reproduce:
>
> Precondition a user 'root' exists with id=1
>
> from django.contrib.auth.models import User
> for result in User.objects.extra(select=
> {'foo3': "SELECT COUNT(auth_user.id) FROM auth_user WHERE
> (auth_user.username = %s)"}
> , select_params=['root']).extra(select=
> {'foo2': "SELECT COUNT(auth_user.id) FROM auth_user WHERE
> (auth_user.id = %s)"}
> , select_params=['1']):
> print result.foo3
> # output should be:
> # 1
> # 1
> for result in User.objects.extra(select=
> {'foo1': "SELECT COUNT(auth_user.id) FROM auth_user WHERE
> (auth_user.username = %s)"}
> , select_params=['root']).extra(select=
> {'foo2': "SELECT COUNT(auth_user.id) FROM auth_user WHERE
> (auth_user.id = %s)"}
> , select_params=['1']):
> print result.foo1
> # output should be:
> # 1
> # 1
New description:
To reproduce:
Precondition a user 'root' exists with id=1
{{{
#!python
from django.contrib.auth.models import User
for result in User.objects.extra(select=
{'foo3': "SELECT COUNT(auth_user.id) FROM auth_user WHERE
(auth_user.username = %s)"}
, select_params=['root']).extra(select=
{'foo2': "SELECT COUNT(auth_user.id) FROM auth_user WHERE
(auth_user.id = %s)"}
, select_params=['1']):
print result.foo3
# output should be:
# 1
# 1
for result in User.objects.extra(select=
{'foo1': "SELECT COUNT(auth_user.id) FROM auth_user WHERE
(auth_user.username = %s)"}
, select_params=['root']).extra(select=
{'foo2': "SELECT COUNT(auth_user.id) FROM auth_user WHERE
(auth_user.id = %s)"}
, select_params=['1']):
print result.foo1
# output should be:
# 1
# 1
}}}
Comment:
The patch looks like it's along the right lines, although I don't really
like adding an `append()` method to the sorted dictionary. That's a bit of
API creep that we can probably avoid.
Fixed milestone and description.
--
Ticket URL: <http://code.djangoproject.com/ticket/7957#comment:3>
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
-~----------~----~----~----~------~----~------~--~---