﻿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
32549	Make `Q(Q(), ...)` equivalent to `Q(...)`	jonathan-golorry	nobody	"Empty Q objects (`Q()` or `~Q()`, etc) evaluate to `False`, but `Q(Q())` evaluates to `True`. This interferes with the shortcut on logical operations involving empty Q objects and can lead to bugs when trying to detect empty operations.
{{{
def q_any(iterable):
    q = Q()
    for element in iterable:
        q |= element
    if q:
        return q
    return Q(pk__in=[])
Item.objects.filter(q_any())  # no items
Item.objects.filter(q_any([Q()]))  # no items
Item.objects.filter(q_any([Q(Q())]))  # all items
}}}

This patch removes empty Q objects from `args` during Q object initialization.

This requires https://code.djangoproject.com/ticket/32548 in order to prevent a regression in logical operations between query expressions and empty Q objects."	Cleanup/optimization	new	Database layer (models, ORM)	dev	Normal		Q objects, nested, empty		Unreviewed	0	0	0	0	0	0
