﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
12807	Empty results break when part of ORs	Samuel Cormier-Iijima	nobody	"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	Database layer (models, ORM)	1.1			query, sql, q, filter, or, empty	sciyoshi@…	Unreviewed	1	0	0	0		
