While exploring the Django transaction stuff (in 1.4rc1), I ran across the following behavior. I use commit_on_success as the example here, but the other transaction decorators/context managers have the same issue.
It seems to me to be a bug, but I wanted to confirm this before I opened an issue. The configuration is running Django using the psycopg2 backend, with 'OPTIONS': { 'autocommit': True, } Consider the following code: from django.db import transaction, DEFAULT_DB_ALIAS, connections from myapp.mymodels import X x = X.objects.get(id=1) print connections[DEFAULT_DB_ALIAS].isolation_level # As expected, it's 0 here. x.myfield = 'Foo' with commit_on_success(): x.save() print connections[DEFAULT_DB_ALIAS].isolation_level # As expected, it's 1 here. print connections[DEFAULT_DB_ALIAS].isolation_level # It's now 1 here, but shouldn't it be back to 0? The bug seems to be that the isolation level does not get reset back to 0, even when leaving connection management. This means that any further operations on the database will open a new transaction (since psycopg2 will automatically open), but this transaction won't be managed in any way. The bug appears to be in django.db.backends.BaseDatabaseWrapper.leave_transaction_management; it calls the _leave_transaction_management hook first thing, but this means that is_managed() will return true (since the decorators call managed(True)), which means that _leave_transaction_management in the psycopg2 backend will not reset the transaction isolation level; the code in the psycopg2 backend seems to assume that it will be run in the new transaction context, not the previous one. Or am I missing something? -- -- Christophe Pettus x...@thebuild.com -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.