The following python program fails at the sess.begin() line when
executed with autocommit set to False.

Specifically, when invoked with a database URI and an argument of 'no'
(or anything except 'yes' or 'true') the following exception is
raised:

sqlalchemy.exc.InvalidRequestError: A transaction is already begun.
Use subtransactions=True to allow subtransactions.

I am using sqlalchemy 0.6.5.
Both postgresql and sqlite fail.

What am I doing wrong?



#! /usr/bin/python
import sys
import logging

import sqlalchemy as sa
import sqlalchemy.orm as sa_orm

logging.basicConfig(level=logging.DEBUG)
logging.getLogger('sqlalchemy').setLevel(logging.DEBUG)

dburi = sys.argv[1]
if sys.argv[2].lower() in [ 'true', 'yes' ]:
  autocommit = True
else:
  autocommit = False

engine = sa.create_engine(dburi)
factory = sa_orm.sessionmaker(bind=engine, autocommit=autocommit,
autoflush=False)
meta = sa.MetaData()
meta.reflect(bind=engine)


sess = factory()
# if autocommit is False, this fails:
sess.begin()


-- 
Jon

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@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