#26552: `TransactionTestCase.serialized_rollback` fails to restore objects due 
to
ordering constraints
-----------------------------------+------------------------------------
     Reporter:  Aymeric Augustin   |                    Owner:  nobody
         Type:  Bug                |                   Status:  new
    Component:  Testing framework  |                  Version:  1.9
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Accepted
    Has patch:  1                  |      Needs documentation:  0
  Needs tests:  1                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+------------------------------------

Comment (by Matthijs Kooijman):

 I've run into a problem related to this one (just reported as #31051), so
 I ended up looking into this problem as well. The original report still
 seems accurate to me, with the proposed solution valid.

 I've been working on a fix and (most of the work), testcase for this
 problem. I'll do some more testing and provide a proper PR for this issue
 and #31051  soon. The testcase is not ideal yet (testing the testing
 framework is tricky), but I'll expand on that in the PR.

 Furthermore, I noticed that `loaddata` does not just wrap everything in a
 transaction, it also explicitly disables constraint checks inside the
 transaction:
 {{{
         with connection.constraint_checks_disabled():
             self.objs_with_deferred_fields = []
             for fixture_label in fixture_labels:
                 self.load_label(fixture_label)
             for obj in self.objs_with_deferred_fields:
                 obj.save_deferred_fields(using=self.using)

         # Since we disabled constraint checks, we must manually check for
         # any invalid keys that might have been added
         table_names = [model._meta.db_table for model in self.models]
         try:
             connection.check_constraints(table_names=table_names)
         except Exception as e:
             e.args = ("Problem installing fixtures: %s" % e,)
             raise
 }}}

 I had a closer look at how this works (since I understood that a
 transaction already implicitly disables constraint checks) and it turns
 out that MySQL/InnoDB is an exception and does *not* defer constraint
 checks to the end of the transaction, but instead needs extra handling (so
 `constraint_checks_disabled()` is a no-op on most database backends). See
 #3615.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/26552#comment:3>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.0cad4d9681795f5a58b3b159d22399b7%40djangoproject.com.

Reply via email to