Re: [sqlalchemy] Migration from 0.5 to 0.9, legacy code and InvalidRequestError: This transaction is inactive
Am Dienstag, 9. September 2014 18:12:26 UTC+2 schrieb Jonathan Vanasco: What do you see if you drop SqlAlchemy's logging to DEBUG? I think I had a similar problem a long time ago, migrating from 0.5 to 0.8. In my case, the issue was with the `Session` factory -- i was not properly creating/deleting `session` objects and they got recycled. So an error raised on one web page request , invalidated the transaction on a completely different web page request. i think there was a slight API change, couple with me doing things the absolute wrong way in 0.5. the only thing I can think of, is tossing in a few `log.debug()` lines to trace your session objects and ensure that you're not accidentally recycling anything. i'd also make sure your current session/sessionmaker setup is in line with mike's current recommendations (which are in both the docs and faq) Thanks for your answers! I actually do have set the log level to DEBUG; sadly I don't get any more useful output. I have read the sessionmaker docs and the faq and have played with all properties when creating my sessions, but to no avail. I suspect my error is similar to yours, though; can you per chance remember what API change triggered your problem? Again, thanks for the answer, I'll go and debug the session lifetime thoroughly. -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] Migration from 0.5 to 0.9, legacy code and InvalidRequestError: This transaction is inactive
unfortunately I can't recall... I encountered this a long time ago (2010 or so), so I think it was a migration from .5 to .6x what i do remember, is that once I figured out how wrong i was about setting up the session... i was amazed that anything worked. I looked at the .5x and .6x changelogs but couldn't find anything (http://docs.sqlalchemy.org/en/rel_0_7/changelog/index.html) another thing i can suggest is this -- try installing a few versions and pinpoint what works/doesn't. it might be easier to find the culprit in the changelog for the first non-working release. -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Migration from 0.5 to 0.9, legacy code and InvalidRequestError: This transaction is inactive
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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] Migration from 0.5 to 0.9, legacy code and InvalidRequestError: This transaction is inactive
On Sep 9, 2014, at 3:30 AM, christian.h.m.schr...@googlemail.com wrote: 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). I'm afraid I don't have much insight, the the code excerpts here aren't telling me anything. I also don't know what you mean by adding Mapper objects. the transaction is inactive usually means you had an exception thrown that was not handled (e.g. session was not rolled back). -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] Migration from 0.5 to 0.9, legacy code and InvalidRequestError: This transaction is inactive
What do you see if you drop SqlAlchemy's logging to DEBUG? I think I had a similar problem a long time ago, migrating from 0.5 to 0.8. In my case, the issue was with the `Session` factory -- i was not properly creating/deleting `session` objects and they got recycled. So an error raised on one web page request , invalidated the transaction on a completely different web page request. i think there was a slight API change, couple with me doing things the absolute wrong way in 0.5. the only thing I can think of, is tossing in a few `log.debug()` lines to trace your session objects and ensure that you're not accidentally recycling anything. i'd also make sure your current session/sessionmaker setup is in line with mike's current recommendations (which are in both the docs and faq) -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.