I'm writing an application in Python using SQLAlchemy (and Elixir) with SQLite as the database backend. I start a new transaction using the code session.begin_transaction()
, but when I call session.rollback()
I get the following error:
sqlalchemy.exceptions.OperationalError: (OperationalError) no such savepoint: sa_savepoint_1 u'ROLLBACK TO SAVEPOINT sa_savepoint_1' []
I also get a similar error calling session.commit()
. From what I can tell, sqlite supports SAVEPOINTS (http://www.sqlite.org/lang_savepoint.html).
How do I get nested transactions to work?
SQLAlchemy uses pysqlite to interact with an SQLite database, if I'm not mistaken pysqlite will by default wrap up any query you send it in a transaction.
The answer might lie in correctly setting the isolation level when you connect.
Some discussion about that over here