Tuesday, October 27, 2009

Django application does not see db changes made by external sources - Django users | Google Groups

I came across an interesting problem today during coding. The update made by one process were not visible in another process. This is an application developed using Django and MySQL.

Turned out that it was the issue of default transaction isolation levels used by InnoDB tables in MySQL. After googling, came across the foll. link:

Django application does not see db changes made by external sources - Django users | Google Groups

The default level for InnoDB is *repeatable read*. In this isolation mode, each transaction gets to work in an isolated version of the table where each row remains as it was when the transaction started. Reading a row is guaranteed to be repeatable.

If you want script1.py (using an InnoDB table) to see committed updates from other transactions you can change the transaction isolation level like so:

from django.db import connection
connection.cursor().execute('set transaction isolation level read committed')

1 comment:

ariellechk said...

Really! It pays the worth of reading, I appreciate your work!


Read on: Terror Strikes