Torsten Landschoff <t.landsch...@gmx.net> added the comment:

The attached patch is my take on this issue. I ran into the problem that during 
schema upgrades dropping a table was not rolled back. In another instance, 
renaming a table was not rolled back. This greatly increases the risk of data 
loss for our application.

Because I do not currently foresee which commands might need dropping out of a 
transaction and because of backwards compatibility woes, I added a new field to 
the sqlite3.Connection: operation_needs_transaction_callback

This function is called to decide if a running transaction should be implicitly 
committed (I'd consider this dangerous), if a transaction has to be started if 
not running (should normally always hold) or if the transaction state should be 
left alone.

For example, the "pragma foreign_keys = ..." is a no-op inside a transaction, 
therefore an implicit begin would be possibly harmful. In our application, we 
enable foreign keys when getting the connection out of the SQLAlchemy pool via 
a pool listener, which would be disabled if there is an implicit begin 
triggered.

The patch also adds a bunch of unit tests to cover the new behaviour.

----------
nosy: +torsten
Added file: http://bugs.python.org/file21417/sqlite_transaction_config_py27.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10740>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to