Opened 7 years ago

Closed 6 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:

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)

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

Download all attachments as: .zip

Change History (7)

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

Attachment: 13579.patch added

patch + simple test

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

Owner: changed from nobody to Filip Gruszczyński

comment:4 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: Bug

comment:5 Changed 6 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 6 years ago by Jacob

Resolution: duplicate
Status: newclosed

Duplicate of #13768.

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