#27504: Cannot Make ORM Queries After an Error and Rollback In Non-autocommit 
Mode
-------------------------------------+-------------------------------------
               Reporter:  Mark       |          Owner:  nobody
  Young                              |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:  Database   |        Version:  1.10
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  1
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 In non-autocommit mode, after an error has occurred (specifcally,
 IntegrityError and ValidationErrors are known to cause the issue, but I
 haven't fully investigated which errors can cause this), the db
 connection's needs_rollback attribute is set to True. When the flag is set
 to True, no further orm queries can be made to the database. Once this has
 happened, there appears to be no way to clean up the transaction, as a
 transaction.rollback() does not unset this flag.

 An example failing scenario:

 {{{
     transaction.set_autocommit(False)
     r1 = Reporter.objects.create(first_name="Archibald",
 last_name="Haddock")
     r2 = Reporter(first_name="Cuthbert", last_name="Calculus", id=r1.id)
     try:
         r2.save(force_insert=True)
     except IntegrityError:
         transaction.rollback()
     # This raises a TransactionManagementError
     last_reporter = Reporter.objects.last()
 }}}

 This ticket is related to https://code.djangoproject.com/ticket/26340 and
 solves a subset of the scenarios affected by it.

--
Ticket URL: <https://code.djangoproject.com/ticket/27504>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.50f691d055323971284d7d7a8cf83b02%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to