Opened 6 years ago

Closed 4 years ago

#13533 closed Bug (duplicate)

queries test fails under MySQL InnoDB

Reported by: Russell Keith-Magee Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2-beta
Severity: Normal Keywords: innodb mysql
Cc: Erik Romijn Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

As of 1.2RC1, the queries test fails under MySQL InnoDB fails at the following test:

Failed example:
    Tag.objects.exclude(children=None)
Expected:
    [<Tag: t1>, <Tag: t3>]
Got:
    [<Tag: t1>, <Tag: t3>, <Tag: t4>]

This is at line 1150 (as of r13252).

This test passes as is under SQLite, Postgres, and MySQL MyISAM.

Even more weird - if you dig into the database at the time the test runs, the query is the same, and the contents of the table is the same. The issue appears to be entirely related to a query cache somewhere in the MySQLdb infrastructure, but only under InnoDB.

You can make the test pass by inserting:

>>> connection.close()

just before the failing test. You can also make the test pass by manually issuing the same query twice, and only checking the test result on the second execution -- i.e., if you modify the test to the following:

>>> r = list(Tag.objects.exclude(children=None))
>>> Tag.objects.exclude(children=None)
[<Tag: t1>, <Tag: t3>]

The test will pass.

Attachments (1)

t13533-tcpdump (13.2 KB) - added by Erik Romijn 6 years ago.
tcpdump of communications with mysql

Download all attachments as: .zip

Change History (12)

comment:1 Changed 6 years ago by Russell Keith-Magee

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

comment:2 Changed 6 years ago by Erik Romijn

Keywords: innodb mysql added

As of r13252? As far as I can see, this was introduced in r12970.

I've played around with transaction isolation levels and query caching, but didn't get any results.

comment:3 Changed 6 years ago by Erik Romijn

Cc: Erik Romijn added

comment:4 Changed 6 years ago by Erik Romijn

Owner: changed from nobody to Erik Romijn
Status: newassigned

comment:5 Changed 6 years ago by Erik Romijn

Owner: changed from Erik Romijn to nobody
Status: assignednew

This would appear to be a MySQL bug, triggered by the testcases.

This problem is triggered by the creation of the ExtraInfo in test_evaluated_queryset_as_argument(), introduced in r12970. Somehow, after that has been done, the same MySQL query yields different results on it's first run, then on subsequent runs.

The query run for the test is:

SELECT `queries_tag`.`id`, `queries_tag`.`name`, `queries_tag`.`parent_id`, `queries_tag`.`category_id` FROM `queries_tag` WHERE NOT
 ((`queries_tag`.`id` IN (SELECT U0.`id` FROM `queries_tag` U0 LEFT OUTER JOIN `queries_tag` U1 ON (U0.`id` = U1.`parent_id`)
WHERE U1.`id` IS NULL) AND NOT (`queries_tag`.`id` IS NULL))) ORDER BY `queries_tag`.`name` ASC LIMIT 21

I have verified this with tcpdump, and MySQL indeed sends back t1, t3 and t4 on the first run, and only t1 and t3 on the second run.
I will attach a log of this.

The insert query for the ExtraInfo looks completely normal:

INSERT INTO `queries_extrainfo` (`info`, `note_id`) VALUES ('good', 1)

Unfortunately a run of the queries suite does over 2000 queries, so it is rather difficult to isolate the problem.
Perhaps someone more experienced can get more out of this.

Changed 6 years ago by Erik Romijn

Attachment: t13533-tcpdump added

tcpdump of communications with mysql

comment:6 Changed 6 years ago by Russell Keith-Magee

The workaround was added to the test case in r15238.

comment:7 Changed 5 years ago by Julien Phalip

Severity: Normal
Type: Bug

comment:8 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

comment:11 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:12 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:13 Changed 4 years ago by Claude Paroz

Resolution: duplicate
Status: newclosed

I think this has been fixed along #16809.

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