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 , 3 years ago
Cc: | added |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 3 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 3 years ago
Has patch: | set |
---|
comment:5 by , 3 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
Thanks for the report. I'm not sure what behavior would be expected, so we should raise
TypeError
.