#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 Xof):
I'd like to offer an opinion on this issue: The current behavior is not a documented, reliable behavior that we need to continue to support. Right now, the current behavior when running with default settings in transaction management on PostgreSQL using psycopg2 is that a transaction gets opened the first time you touch the database. If Django is aware you've modified the database, you get a COMMIT on normal return, ROLLBACK on exception. If you either didn't modify the database, or did but didn't tell Django, you get an open transaction that lasts until some indefinite point in the future. In fact, the next request on the same thread can dive into your same transaction, which strikes me as very buggy. Relying on this behavior is like relying on a particular pattern of uninitialized memory; I don't see any virtue in maintaining it. Thus, I'd suggest that simply enforcing a "commit on return, rollback on exception" throughout the transaction management functionality (middleware, decorators) is the best and easiest answer. -- Ticket URL: <http://code.djangoproject.com/ticket/9964#comment:31> 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.