Hello everyone,
I am currently in the process of migrating a large legacy code base I
inherited from SQLAlchemy 0.5 to 0.9. There is a somewhat confusing stack
of custom decorator magic for connection, session and transaction handling
– too unwieldy to post here in its entirety, but very likely the culprit
for the following problem: This code
@session # custom session decorator
def run(session=None): # session injected here from the decorator
session.begin()
session.add(Table(name='test1')) # 'Table' is some dummy ORM-Mapper
session.commit()
run()
fails with (this is py.test output):
self = <sqlalchemy.engine.base.RootTransaction object at 0x222e1d0>
def commit(self):
"""Commit this :class:`.Transaction`."""
if not self._parent.is_active:
> raise exc.InvalidRequestError("This transaction is inactive")
E InvalidRequestError: This transaction is inactive
../../.virtualenvs/solute/lib/python2.7/site-packages/sqlalchemy/engine/base
.py:1333: InvalidRequestError
The logging of SQLAlchemy looks like this:
INFO:sqlalchemy.engine.base.Engine:BEGIN (implicit)
INFO:sqlalchemy.engine.base.Engine:INSERT INTO test_session_table (name)
VALUES (?)
INFO:sqlalchemy.engine.base.Engine:('test1',)
INFO:sqlalchemy.engine.base.Engine:ROLLBACK
As can be guessed, the session is created with `autocommit=True`, and I
really don't want to change the semantics here (as I said: large legacy
code base, lots of uses for this decorator, no one really understands all
the moving parts any more). I *could* post the session decorator code if
asked for, but I'm not sure it'll be helpful, since it relies on a bunch of
custom connection and pooling magic.
This error only occurs when adding Mapper objects; explicitly executing an
analogous `INSERT` statement instead off the `.add()` works (though with a
spurious `ReferenceError: weakly-referenced object no longer exists`). When
executing explicit `BEGIN`/`COMMIT` statements as well (thus bypassing
SQLAlchemy's transaction handling altogether), not even the ReferenceError
is raised.
I'm well aware that the code I posted doesn't allow for exactly pinpointing
the problem – I merely hoping for some educated guesses on what may go
wrong in our stack, as well as some explanations (like what the
RootTransaction is, and what it means when it's not active).
Many thanks in advance,
Christian
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.