Opened 3 years ago

Closed 3 years ago

#33127 closed Cleanup/optimization (fixed)

"&" and "|" operators are silently ignored after QuerySet.union(), intersection(), and difference().

Reported by: Maxwell Tietze Owned by: Hasan Ramezani
Component: Database layer (models, ORM) Version: 3.1
Severity: Normal Keywords:
Cc: Hasan Ramezani Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This looks like a similar issue to the one fixed in #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.

Change History (6)

comment:1 by Mariusz Felisiak, 3 years ago

Cc: Hasan Ramezani added
Triage Stage: UnreviewedAccepted

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

comment:2 by Hasan Ramezani, 3 years ago

Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:3 by Hasan Ramezani, 3 years ago

comment:4 by Hasan Ramezani, 3 years ago

Has patch: set

comment:5 by Mariusz Felisiak, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In f997c814:

Fixed #33127 -- Added error messages on | and & operators with combined querysets.

Note: See TracTickets for help on using tickets.
Back to Top