On Sep 18, 2010, at 6:52 PM, Randall Nortman wrote:

> In testing my code for concurrency, I discovered that transactions are
> not properly isolated on sqlite, even with
> isolation_level='SERIALIZABLE'.  It turns out that on the sqlite
> dialect, do_begin() does nothing.  As a result, transactions are not
> isolated as expected.  Dirty writes are easy to construct; using the
> ORM:
> 
> (assuming a mapped class Foo with attributes id and bar, and a Foo
> with id=1 existing in the database)
> 
> Process A: foo = Session.query(Foo).filter_by(id=1)
> Process B: foo = Session.query(Foo).filter_by(id=1)
> Process A: foo.bar = 'happy happy'
> Process B: foo.bar = 'joy joy'
> Process A: Session.commit()
> Process B: Session.commit()

Oh and also, when you above say "Process A", "Process B", I assume those are 
separate processes.   The default connection pool used with SQLite is the 
SingletonThreadPool - the same connection is used globally in a thread, so if 
your test above occurs within a single thread, you should select a different 
pool implementation.      See:

http://www.sqlalchemy.org/trac/wiki/FAQ#IamusingmultipleconnectionswithaSQLitedatabasetypicallytotesttransactionoperationandmytestprogramisnotworking

Further rationale on this is available at :  
http://www.sqlalchemy.org/docs/dialects/sqlite.html?highlight=sqlite#threading-behavior




-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to