Opened 15 years ago
Closed 12 years ago
#13198 closed Bug (fixed)
exclude() bug when used with Q() objects
Reported by: | mucisland | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.1 |
Severity: | Normal | Keywords: | exclude Q |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
.exclude() behaves different when its argument is wrapped into Q(). Specifically, when wrapping an exclude filter with Q(), objects containing NULL in related fields are excluded as well as objects which have matching content in this field.
The SQL which is generated by exclude(<field>=<value>) should _not_ match objects with NULL in the respective field, but this is sometimes violated when wrapping the filter with Q(). (So far I've only seen this bug when using a filter which specifies a field in a related object.)
The attached file contains a minimum Django project (project name is "sandbox", application name is "q") with two test cases which should clarify the described behaviour.
Best Regards,
Dirk
Attachments (1)
Change History (6)
by , 15 years ago
Attachment: | sandbox.zip added |
---|
comment:1 by , 15 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
I'm fairly certain that this is a duplicate of #11052; one of the examples in the comments seems to match up.
comment:2 by , 12 years ago
Easy pickings: | unset |
---|---|
Severity: | → Normal |
Type: | → Uncategorized |
UI/UX: | unset |
Still seeing this in Django 1.4, so either it was erroneously marked as a dupe or it snuck back in. It's pretty simple to reproduce:
MyModel.objects.exclude(nullable_field=123) => includes rows with nullable_field=null MyModel.objects.exclude(Q(nullable_field=123)) => excludes rows with nullable_field=null
comment:3 by , 12 years ago
Resolution: | duplicate |
---|---|
Status: | closed → new |
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 12 years ago
Type: | Uncategorized → Bug |
---|
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This was fixed in d3f00bd5706b35961390d3814dd7e322ead3a9a3.
Django project "sandbox" with app "q" which reproduces the bug. Execute "manage.py test".