[Django] #33127: "&" and "|" operators are silently ignored after QuerySet.union(), intersection(), and difference().

1 view
Skip to first unread message

Django

unread,
Sep 21, 2021, 12:47:53 PM9/21/21
to django-...@googlegroups.com
#33127: "&" and "|" operators are silently ignored after QuerySet.union(),
intersection(), and difference().
-------------------------------------+-------------------------------------
Reporter: Maxwell | Owner: nobody
Tietze |
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: 3.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 |
-------------------------------------+-------------------------------------
This looks like a similar issue to the one fixed in
[https://code.djangoproject.com/ticket/27995 #27995]

Example:


{{{
class MyModel(models.Model):
name = models.CharField()

for name in ['a', 'b', 'c']:
MyModel.objects.create(name=name)

group1 = MyModel.objects.filter(name='a')
group2 = MyModel.objects.filter(name='b')
group3 = MyModel.objects.filter(name='c')
combined_group = group1.union(group2)
group_and = combined_group & group1
group_or = combined_group | group 3
}}}

In this example, combined_group, group_and and group_or all have the same
SQL. These operators should raise an exception if they can not be applied
after combinator functions.

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

Django

unread,
Sep 22, 2021, 1:40:32 AM9/22/21
to django-...@googlegroups.com
#33127: "&" and "|" operators are silently ignored after QuerySet.union(),
intersection(), and difference().
-------------------------------------+-------------------------------------
Reporter: Maxwell Tietze | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Hasan Ramezani (added)
* stage: Unreviewed => Accepted


Comment:

Thanks for the report. I'm not sure what behavior would be expected, so we
should raise `TypeError`.

--
Ticket URL: <https://code.djangoproject.com/ticket/33127#comment:1>

Django

unread,
Sep 22, 2021, 2:48:48 AM9/22/21
to django-...@googlegroups.com
#33127: "&" and "|" operators are silently ignored after QuerySet.union(),
intersection(), and difference().
-------------------------------------+-------------------------------------
Reporter: Maxwell Tietze | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* owner: nobody => Hasan Ramezani
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/33127#comment:2>

Django

unread,
Sep 23, 2021, 1:00:59 PM9/23/21
to django-...@googlegroups.com
#33127: "&" and "|" operators are silently ignored after QuerySet.union(),
intersection(), and difference().
-------------------------------------+-------------------------------------
Reporter: Maxwell Tietze | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Hasan Ramezani):

[https://github.com/django/django/pull/14890 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/33127#comment:3>

Django

unread,
Sep 23, 2021, 1:01:16 PM9/23/21
to django-...@googlegroups.com
#33127: "&" and "|" operators are silently ignored after QuerySet.union(),
intersection(), and difference().
-------------------------------------+-------------------------------------
Reporter: Maxwell Tietze | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33127#comment:4>

Django

unread,
Sep 24, 2021, 12:46:09 AM9/24/21
to django-...@googlegroups.com
#33127: "&" and "|" operators are silently ignored after QuerySet.union(),
intersection(), and difference().
-------------------------------------+-------------------------------------
Reporter: Maxwell Tietze | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33127#comment:5>

Django

unread,
Sep 24, 2021, 1:41:48 AM9/24/21
to django-...@googlegroups.com
#33127: "&" and "|" operators are silently ignored after QuerySet.union(),
intersection(), and difference().
-------------------------------------+-------------------------------------
Reporter: Maxwell Tietze | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: closed

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"f997c81472b96a1cf48a1a19a4fe974683455a50" f997c814]:
{{{
#!CommitTicketReference repository=""
revision="f997c81472b96a1cf48a1a19a4fe974683455a50"
Fixed #33127 -- Added error messages on | and & operators with combined
querysets.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33127#comment:6>

Reply all
Reply to author
Forward
0 new messages