Michael Bayer wrote:
On Mar 12, 2010, at 6:54 AM, Chris Withers wrote:
Got this error this morning:
File
"/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/orm/session.py",
line 247, in _assert_is_active
"The transaction is inactive due to a rollback in a "
sqlalchemy.exc.InvalidRequestError: The transaction is inactive due to a
rollback in a subtransaction. Issue rollback() to cancel the transaction.
I didn't think our app was using subtransactions.
What pattern(s) of code should I be looking for to find whatever might have
casued this?
Seems to have been an annoyingly transient error...
here's a very comprehensive set of answers:
http://www.sqlalchemy.org/trac/wiki/FAQ#Thetransactionisinactiveduetoarollbackinasubtransaction
make sure you keep reading on through the subsequent question/answers after
your initial disatisfaction with the first answer
Okay, so basically, we should use:
try:
<use session>
session.commit()
except:
session.rollback()
raise
finally:
session.remove()
The structure I've traditionally used with transactions has been:
try:
<use session>
except:
log()
session.rollback()
else:
session.commit()
Is this okay? Why would the first setup be preferable?
Also, what's the difference between session.remove() and
session.close()? What does session.remove() do when you're not using
scoped_session?
cheers,
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
--
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.