Opened 18 years ago

Closed 18 years ago

#2457 closed defect (invalid)

manytomany __id__in filters do not work correctly with the sqlite3 backend

Reported by: gabor@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

imagine the following models:

class A(Model):
    name = CharField(maxlength=200)

class B(Model):
    title = CharField(maxlength=200)
    rel = ManyToManyField(A)

now, if i create the following instances:

a1 = A.objects.create( name='a1')
a2 = A.objects.create( name='a2')

b1 = B.objects.create( title='b1')
b2 = B.objects.create( title='b2')

b1.rel = [a1]
b2.rel = [a2]

b1.save()
b2.save()

and now do the following queries:

B.objects.filter(rel__id = a1.id)
B.objects.filter(rel__id__in = [a1.id])

i should get identical results. but no.
i get:

[<B: b1>]
[<B: b1>, <B: b2>]

which is incorrect.
the correct answer would be

[<B: b1>]
[<B: b1>]

with postgresql backend this works correctly.

also when filtering using non-id fields, the "in filtering" works ok in sqlite3.
for example these two queries generate identical (and correct) results in sqlite3:

B.objects.filter(rel__name = 'a1')
B.objects.filter(rel__name__in = ['a1'])

[<B: b1>]
[<B: b1>]

i tested this on mac-osx, sqlite 3.3.5, python 2.4.2 (from darwinports)

Change History (2)

comment:1 by Gábor Farkas <gabor@…>, 18 years ago

it seems it was a bug in sqlite3, which is fixed in sqlite3 3.3.6

( see this discussion: http://thread.gmane.org/gmane.comp.db.sqlite.general/23546/focus=23568 )

i will verify if using a newer sqlite3 indeed fixes this bug, and the close this ticket

comment:2 by Gábor Farkas <gabor@…>, 18 years ago

Resolution: invalid
Status: newclosed

ok, tried it with sqlite3 3.3.8, and it's working, so i'll close this ticket.

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