Opened 16 years ago

Closed 16 years ago

Last modified 5 years ago

#7572 closed (fixed)

Fixture loading succeeds, but leads to bad query results for test cases under MySQL

Reported by: Russell Keith-Magee Owned by: Russell Keith-Magee
Component: Testing framework Version: dev
Severity: Keywords: mysql fixture exclude
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

MySQL ticket 37735 describes a situation where queries can return unexpected results. If a single connection object is used to create a table, populate that table, then query the rows in the table, it is possible for the query to return unexpected results. In turn, this can cause a problem for Django test cases, as test tables are created, populated and queried using the same connection.

To demonstrate the problem, create a set of tables and test cases that follows the example in the MySQL ticket:

  • An Article and a Channel model, with each Article having an m2m relationship with Channel.
  • 1 Channel object
  • 9 Article objects (with primary keys 1-9), each with the single channel in their m2m table.

Then run:

>>> Article.objects.exclude(pk=9).values_list('id',flat=True)
[1,2,3,4,5,6,7,8,9]

The article with pk=9 should not be in this return set, but under MySQL, it will be. Postgres and SQLite return the expected result.

It's also important to have lots of data - if you only have 1 or 2 articles, the error doesn't occur. 9 seems to be the minimum.

Change History (3)

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

Triage Stage: UnreviewedAccepted

I will commit a patch for this shortly.

comment:2 by Russell Keith-Magee, 16 years ago

Resolution: fixed
Status: newclosed

(In [7803]) Fixed #7572 -- Force the closure of the database connection at the end of fixture loading as a workaround for MySQL bug #37735. Thanks to Simon Litchfield for his help in narrowing down this issue.

Last edited 5 years ago by Tim Graham (previous) (diff)

comment:3 by Jacob, 13 years ago

milestone: 1.0 beta

Milestone 1.0 beta deleted

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