Opened 15 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)

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

Download all attachments as: .zip

Change History (7)

comment:1 by Russell Keith-Magee, 15 years ago

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

by Filip Gruszczyński, 15 years ago

Attachment: 13579.patch added

patch + simple test

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

Owner: changed from nobody to Filip Gruszczyński

comment:4 by Julien Phalip, 14 years ago

Severity: Normal
Type: Bug

comment:5 by dmclain, 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.

comment:6 by Jacob, 14 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #13768.

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