* needs_better_patch: 0 => 1
* easy: => 0
Comment:
12807.patch fails to apply cleanly on to trunk
--
Ticket URL: <http://code.djangoproject.com/ticket/12807#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> The following query:
>
> User.objects.filter((Q(pk=3) | ~Q(pk__in=[]) & Q(pk=1))
>
> currently breaks, since ~Q(pk__in=[]) isn't noticed as being full, thus
> leading to the following query:
>
> >>> User.objects.filter((Q(pk=3) | ~Q(pk__in=[])) &
> Q(pk=1)).values('id').query.as_sql()
> ('SELECT "auth_user"."id" FROM "auth_user" WHERE (("auth_user"."id" =
> %s ) AND "auth_user"."id" = %s )', (3, 1))
>
> and giving an empty result set, instead of the correct
>
> >>> User.objects.filter((Q(pk=3) | ~Q(pk__in=[])) &
> Q(pk=1)).values('id').query.as_sql()
> ('SELECT "auth_user"."id" FROM "auth_user" WHERE ("auth_user"."id" =
> %s )', (1,))
>
> which returns the single user with PK 1.
>
> Attaching a patch which fixes it by making as_sql() raise FullResultSet
> and adds a test case. The issue could also be fixed by checking if the
> child's as_sql() is empty, but this seemed cleaner.
New description:
The following query:
`User.objects.filter((Q(pk=3) | ~Q(pk__in=[]) & Q(pk=1))`
currently breaks, since `~Q(pk__in=[])` isn't noticed as being full, thus
leading to the following query:
>>> `User.objects.filter((Q(pk=3) | ~Q(pk__in=[])) &
Q(pk=1)).values('id').query.as_sql()`
('SELECT "auth_user"."id" FROM "auth_user" WHERE (("auth_user"."id" =
%s ) AND "auth_user"."id" = %s )', (3, 1))
and giving an empty result set, instead of the correct
>>> `User.objects.filter((Q(pk=3) | ~Q(pk__in=[])) &
Q(pk=1)).values('id').query.as_sql()`
('SELECT "auth_user"."id" FROM "auth_user" WHERE ("auth_user"."id" =
%s )', (1,))
which returns the single user with PK 1.
Attaching a patch which fixes it by making as_sql() raise FullResultSet
and adds a test case. The issue could also be fixed by checking if the
child's as_sql() is empty, but this seemed cleaner.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/12807#comment:7>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"58c6d0209d71872f0682d478921db1e00496e16c"]:
{{{
#!CommitTicketReference repository=""
revision="58c6d0209d71872f0682d478921db1e00496e16c"
Fixed #12807 -- EmptyResultSet ORed condition
The EmptyResultSet wasn't treated correctly so the end results was
incorrect, too. The bug had been already fixed in master so only tests
added.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/12807#comment:8>