Django

Code

Ticket #7572 (closed: fixed)

Opened 2 months ago

Last modified 2 months ago

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

Reported by: russellm Assigned to: russellm
Milestone: 1.0 beta Component: Unit test system
Version: SVN Keywords: mysql fixture exclude
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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.

Attachments

Change History

06/30/08 06:28:36 changed by russellm

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

I will commit a patch for this shortly.

06/30/08 07:18:30 changed by russellm

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

(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.


Add/Change #7572 (Fixture loading succeeds, but leads to bad query results for test cases under MySQL)




Change Properties
Action