Fixture loading succeeds, but leads to bad query results for test cases under MySQL
|Reported by:||russellm||Owned by:||russellm|
|Severity:||Keywords:||mysql fixture exclude|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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.
>>> 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 Changed 6 years ago by russellm
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted