Django

Code

Ticket #2457 (closed: invalid)

Opened 2 years ago

Last modified 2 years ago

manytomany __id__in filters do not work correctly with the sqlite3 backend

Reported by: gabor@nekomancer.net Assigned to: adrian
Milestone: Component: Database wrapper
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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)

Attachments

Change History

11/16/06 18:33:59 changed by Gábor Farkas <gabor@nekomancer.net>

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

11/20/06 09:39:48 changed by Gábor Farkas <gabor@nekomancer.net>

  • status changed from new to closed.
  • resolution set to invalid.

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


Add/Change #2457 (manytomany __id__in filters do not work correctly with the sqlite3 backend)




Change Properties
Action