Opened 17 years ago

Closed 16 years ago

#6559 closed (fixed)

Lookups using m2m relationships return incorrect results with Sqlite on Windows

Reported by: Manoj Govindan <egmanoj@…> Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords:
Cc: egmanoj@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Consider the following model

from django.db import models
from django.contrib.auth.models import User

class Book(models.Model):
    name = models.CharField(max_length = 255, unique = True)
    users = models.ManyToManyField(User)

m2m lookups using username attribute of User are returning incorrect results with Sqlite only on Windows. It seems that the filtering condition is being ignored and all books are being returned for any given username.

Book.objects.filter(users__username = <some username> )

as well as

Book.objects.filter(users__username_exact = <some username> )

are not working properly.

I have added tests for the same.

Attachments (1)

m2m_sqlite_windows.diff (4.3 KB ) - added by Manoj Govindan <egmanoj@…> 17 years ago.
Tests for the defect.

Download all attachments as: .zip

Change History (6)

by Manoj Govindan <egmanoj@…>, 17 years ago

Attachment: m2m_sqlite_windows.diff added

Tests for the defect.

comment:1 by Manoj Govindan <egmanoj@…>, 17 years ago

Cc: egmanoj@… added

comment:2 by Malcolm Tredinnick, 17 years ago

For those of us not running Windows, what results *do* you see when you run this test? Which test fails?

Also, which version of SQLite are you using to test this?

in reply to:  2 comment:3 by Manoj Govindan <egmanoj@…>, 17 years ago

Replying to mtredinnick:

For those of us not running Windows, what results *do* you see when you run this test? Which test fails?

Four out of the five tests I have added are failing. The first one is a look up of all books. That works as expected. Subsequent tests are look ups of books based on user names, both with and without the __exact check.

Results can be seen below.

======================================================================
FAIL: Doctest: modeltests.m2m_sqlite_windows.models.__test__.API_TESTS
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python25\lib\site-packages\django\test\_doctest.py", line 2180, in ru
nTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for modeltests.m2m_sqlite_windows.models.__t
est__.API_TESTS
  File "D:\manoj\projects\django_tests\modeltests\m2m_sqlite_windows\models.py",
 line unknown line number, in API_TESTS

----------------------------------------------------------------------
File "D:\manoj\projects\django_tests\modeltests\m2m_sqlite_windows\models.py", l
ine ?, in modeltests.m2m_sqlite_windows.models.__test__.API_TESTS
Failed example:
    Book.objects.filter(users__username = 'twoface')
Expected:
    [<Book: My Lives: Two Face>, <Book: Why we don't need Batman>]
Got:
    [<Book: My Lives: Two Face>, <Book: Why we don't need Batman>, <Book: Global
 Warming: The Looming Danger>]
----------------------------------------------------------------------
File "D:\manoj\projects\django_tests\modeltests\m2m_sqlite_windows\models.py", l
ine ?, in modeltests.m2m_sqlite_windows.models.__test__.API_TESTS
Failed example:
    Book.objects.filter(users__username__exact = 'twoface')
Expected:
    [<Book: My Lives: Two Face>, <Book: Why we don't need Batman>]
Got:
    [<Book: My Lives: Two Face>, <Book: Why we don't need Batman>, <Book: Global
 Warming: The Looming Danger>]
----------------------------------------------------------------------
File "D:\manoj\projects\django_tests\modeltests\m2m_sqlite_windows\models.py", l
ine ?, in modeltests.m2m_sqlite_windows.models.__test__.API_TESTS
Failed example:
    Book.objects.filter(users__username = 'penguin')
Expected:
    [<Book: Global Warming: The Looming Danger>]
Got:
    [<Book: My Lives: Two Face>, <Book: Why we don't need Batman>, <Book: Global
 Warming: The Looming Danger>]
----------------------------------------------------------------------
File "D:\manoj\projects\django_tests\modeltests\m2m_sqlite_windows\models.py", l
ine ?, in modeltests.m2m_sqlite_windows.models.__test__.API_TESTS
Failed example:
    Book.objects.filter(users__username__exact = 'penguin')
Expected:
    [<Book: Global Warming: The Looming Danger>]
Got:
    [<Book: My Lives: Two Face>, <Book: Why we don't need Batman>, <Book: Global
 Warming: The Looming Danger>]


----------------------------------------------------------------------
Ran 1 test in 0.437s

FAILED (failures=1)

Also, which version of SQLite are you using to test this?

I am using v3.5.4

Interestingly enough the generated queries for the lookups worked fine when I executed them using the sqlite client.

comment:4 by Manoj Govindan <egmanoj@…>, 16 years ago

This bug seems to have been fixed in revision 7540. At least I could not reproduce it and the tests are passing. Can someone verify and close the ticket please?

comment:5 by Karen Tracey <kmtracey@…>, 16 years ago

Resolution: fixed
Status: newclosed

Confirmed this has been fixed. I was able to recreate the error on r7092 (which was probably approximately the 'current' revision when this ticket was opened) and my Windows XP box. The same tests run without errors using today's trunk (r7787).

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