Opened 9 years ago

Closed 8 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


from django.db import models

class A(models.Model):
  b = models.ForeignKey(B, null=True)

class B(models.Model):

for _ in range(0,10):

b = B.objects.create()

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)

13579.patch (1.9 KB) - added by Filip Gruszczyński 9 years ago.
patch + simple test

Download all attachments as: .zip

Change History (7)

comment:1 Changed 9 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

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)"

Changed 9 years ago by Filip Gruszczyński

Attachment: 13579.patch added

patch + simple test

comment:2 Changed 9 years ago by Filip Gruszczyński

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 Changed 9 years ago by Filip Gruszczyński

Owner: changed from nobody to Filip Gruszczyński

comment:4 Changed 8 years ago by Julien Phalip

Severity: Normal
Type: Bug

comment:5 Changed 8 years ago by dmclain

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.

comment:6 Changed 8 years ago by Jacob

Resolution: duplicate
Status: newclosed

Duplicate of #13768.

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