Nested transactions with SQLAlchemy and sqlite

461 views
Skip to first unread message

Jon

unread,
Nov 1, 2009, 4:13:44 AM11/1/09
to sqlalchemy
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).

So, how do I get nested transactions to work?

I've also posted the question on stack overflow, so you can reply
there if you like, or here, I don't mind.

Michael Bayer

unread,
Nov 1, 2009, 1:44:25 PM11/1/09
to sqlal...@googlegroups.com

our current tests disable SAVEPOINT testing for the sqlite3 DBAPI, as
it does not appear to understand the "SAVEPOINT" instruction. If I
enable a simple SAVEPOINT test, I get this output:

sqlalchemy.engine.base.Engine.0x...fd50: INFO: BEGIN
sqlalchemy.engine.base.Engine.0x...fd50: INFO: INSERT INTO query_users
(user_id, user_name) VALUES (?, ?)
sqlalchemy.engine.base.Engine.0x...fd50: INFO: [1, 'user1']
sqlalchemy.engine.base.Engine.0x...fd50: INFO: SAVEPOINT sa_savepoint_1
sqlalchemy.engine.base.Engine.0x...fd50: INFO: []
sqlalchemy.engine.base.Engine.0x...fd50: INFO: INSERT INTO query_users
(user_id, user_name) VALUES (?, ?)
sqlalchemy.engine.base.Engine.0x...fd50: INFO: [2, 'user2']
sqlalchemy.engine.base.Engine.0x...fd50: INFO: RELEASE SAVEPOINT
sa_savepoint_1
sqlalchemy.engine.base.Engine.0x...fd50: INFO: []

and then the same error you're getting, i.e.

OperationalError: (OperationalError) no such savepoint: sa_savepoint_1

u'RELEASE SAVEPOINT sa_savepoint_1' []

If you can research for us the correct way for the pysqlite DBAPI to
understand a SAVEPOINT conversation, it can be implemented.

Jon Black

unread,
Nov 2, 2009, 5:48:59 AM11/2/09
to sqlal...@googlegroups.com
A quick search on google revealed this: http://74.125.77.132/search?q=cache:YB8OTfrO6xAJ:itsystementwicklung.de/pipermail/list-pysqlite/2009-June/000414.html+pipermail/list-pysqlite/2009-June/000414.html&cd=1&hl=nl&ct=clnk&gl=nl&client=firefox-a

Whilst the solution doesn't help, it does mention that it's not supported in pysqlite. So perhaps we need to talk with them?

2009/11/1 Michael Bayer <mik...@zzzcomputing.com>

Jon Black

unread,
Nov 2, 2009, 6:10:27 AM11/2/09
to sqlal...@googlegroups.com
I've also found this as well, which references the previous link: http://www.mail-archive.com/sqlal...@googlegroups.com/msg15411.html

2009/11/2 Jon Black <juan....@gmail.com>
Reply all
Reply to author
Forward
0 new messages