Opened 14 years ago
Closed 14 years ago
#13579 closed Bug (duplicate)
None gets ignored by __in filter
Reported by: | Martin Chase | Owned by: | Filip Gruszczyński |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
from django.db import models class A(models.Model): b = models.ForeignKey(B, null=True) class B(models.Model): pass for _ in range(0,10): A.objects.create() b = B.objects.create() A.objects.create(b=b) A.objects.filter(b=None).count() # => 10 A.objects.filter(b__in=[None,]).count() # => 0 (should be 10) A.objects.filter(b__in=[None,b]).count() # => 1 (should be 11) A.objects.filter(b__in=[b,None]).count() # => 1 (should be 11)
I haven't tested with the above code exactly, but this is the failing behavior I'm seeing.
Attachments (1)
Change History (7)
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 14 years ago
Has patch: | set |
---|
I don't know, whether this is a way to go, so I would appreciate any advice on the patch and would be happy to work more on it, if required.
comment:3 by , 14 years ago
Owner: | changed from | to
---|
comment:4 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:5 by , 14 years ago
Easy pickings: | unset |
---|---|
Patch needs improvement: | set |
Looks like the implementation for __in
has changed since the patch was made. This is more than just the patch not applying cleanly, there are more code paths that need to be considered now.
Note:
See TracTickets
for help on using tickets.
This is an edge case caused by the fact that x = NULL and x IS NULL are not equivalent in SQL. The filter clause "bin=[None, value]" needs to be rolled out as "b IS NULL OR b IN (value)"