#18984: TransactionTestCase._fixture_teardown locks under mysql
-----------------------------------+-------------------------------------
     Reporter:  jdunck             |                    Owner:  aaugustin
         Type:  Bug                |                   Status:  new
    Component:  Testing framework  |                  Version:  master
     Severity:  Release blocker    |               Resolution:
     Keywords:                     |             Triage Stage:  Accepted
    Has patch:  1                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+-------------------------------------

Comment (by aaugustin):

 I finally managed to reproduce the problem with `TransactionTestCase` and
 `TEST_MIRROR` but without `multi_db = True`.

 In order to create a pending transaction, I made a raw SQL query and
 didn't call `commit_unless_managed()`. This is obviously incorrect, but I
 can imagine this sequence happening accidentally — for instance if an
 exception is raised in a test before calling `commit_unless_managed()`.

 I've attached a test case as a patch, but I don't intend to commit it, for
 the reasons explained above.

 ----

 To fix the problem, I had to `rollback_unless_managed()` all connections,
 and not only the default connection like the pull request does, because
 `multi_db = False`. I think the PR worked for Jeremy's case because he
 only had a pending transaction on the default connection. If so, rolling
 back the transaction on the default connection was enough.

 Of course, if I had set `multi_db = True`, the PR would have rolled back
 the transactions on all databases. But currently that doesn't work at all.
 I think it's best to avoid deadlocks even in the case of programming
 mistakes, and calling `rollback_unless_managed()` is inexpensive when the
 connection hasn't been used.

 I've also attached a patch that implements this solution.

 ----

 I propose to commit this patch and open a new ticket for the
 `TransactionTestCase` + `TEST_MIRROR` + `multi_db = True` combination.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18984#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to