Code

Opened 8 years ago

Closed 8 years ago

#2457 closed defect (invalid)

manytomany __id__in filters do not work correctly with the sqlite3 backend

Reported by: gabor@… Owned by: adrian
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: UI/UX:

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 (0)

Change History (2)

comment:1 Changed 8 years ago by Gábor Farkas <gabor@…>

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 Changed 8 years ago by Gábor Farkas <gabor@…>

  • Resolution set to invalid
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.