Hello, Just in case I have a "XY problem", the actual problem I'm trying to solve is that I want to be able to read data from two unrelated models and make sure that the data from each appeared to come from the same instant in time. In the database, I'd use:
BEGIN; SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; SELECT stuff FROM a; SELECT other_stuff FROM b; ROLLBACK; So, what I believe I should be aiming to do in Django is to change the default READ COMMITTED isolation level to SERIALIZABLE. I am unsure if this is possible. I'm using Django SVN release with the postgresql_psycopg2 with PostgreSQL 8.4.3. I notice that by default, the following preamble queries are emitted prior to any selects when retrieving data from a model: SET DATESTYLE TO 'ISO' SHOW client_encoding SHOW default_transaction_isolation BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED SELECT version() -- This one happens only sometimes. SET TIME ZONE E'Asia/Singapore' Followed by: SELECT ... ROLLBACK I would like to know if there is any way I can change the transaction isolation level for a particular view function? If not, is this planned for a future release? Also, if there is no current method to change this, what workaround would you recommend? I have read http://docs.djangoproject.com/en/dev/topics/db/transactions/ but could not see how to do what I need, the commit_manually decorator does not stop the above preamble queries. Currently I am forcing a rollback then I start a new transaction with the desired isolation level, like so: def func(request, parameters): cursor = connection.cursor() cursor.execute("ROLLBACK;") cursor.execute("BEGIN; SET TRANSACTION ISOLATION LEVEL SERIALIZABLE") # Access models here Obviously, this is suboptimal for a number of reasons. If I simply try to set transaction isolation level without ending the transaction and beginning a new one, I will get an error that it can't be applied after any other select statement (see select version() above). Cheers, Chris Young -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.