#9964: Transaction middleware closes the transaction only when it's marked as dirty ------------------------------------------+--------------------------------- Reporter: ishirav | Owner: nobody Status: new | Milestone: Component: Database layer (models, ORM) | Version: 1.0-beta-1 Keywords: transactions | Stage: Unreviewed Has_patch: 0 | ------------------------------------------+--------------------------------- The transaction middleware commits only dirty transactions on success, and rolls back only dirty transactions in case of an error.
This means that any transaction that only SELECTs data gets rolled back (I'm not sure by whom - the database itself, perhaps?). So this is what I see in my PostgreSQL log: {{{ BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED SET TIME ZONE E'America/Chicago' SELECT ... SELECT ... SELECT ... ROLLBACK }}} The expected behavior is a COMMIT (except in case of an error). Typically this does not cause any problems, because it affects only non- dirty transactions. However if you use raw SQL to make database modifications, it will be rolled back unless the dirty flag gets set by some another part of your code. This can result in loss of data, and a very hard to find bug... The correct behavior would be to always close the transaction, regardless of the dirty flag. Meaning that TransactionMiddleware.process_response should always call transaction.commit(), and TransactionMiddleware.process_exception should always call transaction.rollback() This bug is also the cause of tickets #9763 and #9919 -- Ticket URL: <http://code.djangoproject.com/ticket/9964> 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-updates@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 -~----------~----~----~----~------~----~------~--~---