Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#7572 closed (fixed)

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

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

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

Change History (3)

comment:1 Changed 6 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

I will commit a patch for this shortly.

comment:2 Changed 6 years ago by russellm

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

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

comment:3 Changed 3 years ago by jacob

  • milestone 1.0 beta deleted

Milestone 1.0 beta deleted

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.