#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 seanc):
Thanks to @jmoiron for providing the following snippet which solved my johnny-cache problem and lets me continue to use TransactionMiddleware. shai, would be interested in any comments that you have regarding this, but for the time being, I think I'm set. I think the default behavior at this point in time should be COMMIT, not ROLLBACK (both for performance reasons for MySQL and for Johnny-cache reasons). The web request was successful, therefore the database should match the HTTP state. {{{ # Use the following in settings.py MIDDLEWARE_CLASSES = ( 'lib.transaction_middleware.TransactionMiddlewareCommit', ) }}} {{{ # And transaction_manager.py from django.middleware.transaction import TransactionMiddleware from django.db import transaction class TransactionMiddlewareCommit(TransactionMiddleware): def process_response(self, request, response): if transaction.is_managed(): try: transaction.commit() except: pass transaction.leave_transaction_management() return response class TransactionMiddlewareOpen(TransactionMiddleware): def process_response(self, request, response): return super(TransactionMiddleware, self).process_response(req, request, response) class TransactionMiddlewareRollback(TransactionMiddleware): def process_response(self, request, response): if transaction.is_managed(): try: transaction.commit() except: pass transaction.leave_transaction_management() return response }}} -- Ticket URL: <http://code.djangoproject.com/ticket/9964#comment:25> 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.