Opened 12 years ago
Closed 12 years ago
#6074 closed (fixed)
QOr doesn't handle two empty ResultSets correctly
Reported by: | Honza Král | Owned by: | Raphaël Braud |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | master |
Severity: | Keywords: | or Q sql sprintdec01 qs-rf-fixed | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
>>> from django.db.models import Q >>> from django.contrib.auth.models import User >>> User.objects.filter( Q( id__in=[] ) | Q( id__in=[] ) )
Should be empty queryset, but is not
whe generated WHERE clause is empty, the problem seems to be around
django/db/models/query.py:725
Attachments (5)
Change History (18)
comment:1 Changed 12 years ago by
Owner: | changed from nobody to Raphaël Braud |
---|---|
Status: | new → assigned |
Changed 12 years ago by
Attachment: | patch.diff added |
---|
comment:2 Changed 12 years ago by
Has patch: | set |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
comment:3 Changed 12 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:4 Changed 12 years ago by
Has patch: | unset |
---|
comment:5 Changed 12 years ago by
Keywords: | sprintdec01 added |
---|
Changed 12 years ago by
Attachment: | 6074-queryset-refactor.diff added |
---|
fixes the same problem for queryset-refactor branch
Changed 12 years ago by
Attachment: | 6074_2.diff added |
---|
comment:6 follow-up: 7 Changed 12 years ago by
Keywords: | qs-rf added |
---|---|
Triage Stage: | Unreviewed → Accepted |
Any patches against query creation for trunk aren't likely to survive at the moment, since queryset-refactor is very advanced. I have a feeling this is going to be fixed naturally in that branch (there are some known problems with disjunctive joins at the moment, but they'll be fixed). I'll close this once I've verified it's fixed there and the branch is merged.
comment:7 Changed 12 years ago by
Replying to mtredinnick:
Any patches against query creation for trunk aren't likely to survive at the moment, since queryset-refactor is very advanced. I have a feeling this is going to be fixed naturally in that branch (there are some known problems with disjunctive joins at the moment, but they'll be fixed). I'll close this once I've verified it's fixed there and the branch is merged.
One of the patches fixes the problem in qs-rf branch, where the problem exists as well. ( 6074-queryset-refactor.diff )
comment:8 Changed 12 years ago by
Has patch: | set |
---|
comment:9 follow-up: 10 Changed 12 years ago by
Unfortunately, that doesn't fix it properly in the queryset-refactor branch. There is some more general work required to make disjunctions work correctly there (which is why three tests are currently failing in that branch: to remind me to fix that properly). Thanks for trying, anyway. It's just a bit trickier than it looks because this is a special case of something more general.
comment:10 Changed 12 years ago by
Replying to mtredinnick:
Unfortunately, that doesn't fix it properly in the queryset-refactor branch. There is some more general work required to make disjunctions work correctly there (which is why three tests are currently failing in that branch: to remind me to fix that properly). Thanks for trying, anyway. It's just a bit trickier than it looks because this is a special case of something more general.
I didn't presume to fix the whole QOr behavior in qs-rf branch - the patch I supplied merely fixed this little issue (the tests attached failed without it and passes with it).
comment:11 Changed 12 years ago by
comment:12 Changed 12 years ago by
Keywords: | qs-rf-fixed added; qs-rf removed |
---|
comment:13 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
(In [7477]) Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
still an issue in this case :
User.objects.filter( Q( idin=[]) | Q( idin=[1,]) | Q(idin=[] ) )