#9964: Transaction middleware closes the transaction only when it's marked as
dirty
---------------------------------------------------+------------------------
          Reporter:  ishirav                       |         Owner:  
mtredinnick 
            Status:  assigned                      |     Milestone:  1.3        
 
         Component:  Database layer (models, ORM)  |       Version:  1.0-beta-1 
 
        Resolution:                                |      Keywords:  
transactions
             Stage:  Accepted                      |     Has_patch:  1          
 
        Needs_docs:  1                             |   Needs_tests:  0          
 
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by shai):

 After looking into other stuff, and then coming back to this, I realized I
 was sorely mistaken in the analysis above.

 In fact, Django closes all the connections (at least, all the connections
 it manages) at the end of every request (this is done with a signal-
 handler that is defined at django/db/__init__.py circa line 85). Thus, no
 performance is gained by leaving transactions dangling, and there is no
 danger of phantom bugs with a transaction being stretched across requests.
 The problem starts and almost ends, with the cases that have actually been
 reported -- using raw sql does not mark a transaction as dirty when it
 should. "Almost", because all that's left is the non-issue of read-only
 transactions which are being rolled back rather than committed.

 I'm attaching a new patch. The new approach is: Whenever anybody touches a
 cursor in a managed transaction, that transaction becomes dirty. It is not
 entirely backwards-compatible: Some user code which used manual commit
 will break, because leaving a read-only transaction pending is no longer
 considered acceptable. This was, in fact, the case with one of the
 fixtures_regress tests (a fix for the test is included in the patch). The
 patch also removes the note about needing to set_dirty with raw sql from
 the documentation.

 Your criticism is welcome.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9964#comment:38>
Django <http://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 django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to