﻿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
33963	Combining Q objects with empty querysets crashes.	Bogumil Schube	nobody	"Working example with django 4.0


{{{
from django.db import models
from django.db.models import Q

class Test(models.Model):
   pass

out = Test.objects.none()
for a, b in [(1,1),(2,2),(3,3)]:
   out |= Q(a=a, b=b)

> out
> Out[23]: <Q: (OR: (AND: ('a', 1), ('b', 1)), (AND: ('a', 2), ('b', 2)), (AND: ('a', 3), ('b', 3)))>

}}}

In django 4.1 it's resulting in an AttributeError

{{{
site-packages/django/db/models/query.py:1951, in QuerySet._check_operator_queryset(self, other, operator_)
   1950 def _check_operator_queryset(self, other, operator_):
-> 1951     if self.query.combinator or other.query.combinator:
   1952         raise TypeError(f""Cannot use {operator_} operator with combined queryset."")

AttributeError: 'Q' object has no attribute 'query'

}}}

This error (or feature?) seems to come from #33127"	Bug	closed	Database layer (models, ORM)	4.1	Normal	invalid			Unreviewed	0	0	0	0	0	0
