[Django] #33963: Combining Q objects

10 views
Skip to first unread message

Django

unread,
Aug 29, 2022, 5:31:59 AM8/29/22
to django-...@googlegroups.com
#33963: Combining Q objects
-------------------------------------+-------------------------------------
Reporter: Bogumil | Owner: nobody
Schube |
Type: Bug | Status: new
Component: Database | Version: 4.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/33963>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages