[Sqlalchemy-tickets] Issue #3974: Inconsistent session state after raising exception in after_commi
Brought to you by:
zzzeek
From: Oleg L. <iss...@bi...> - 2017-04-28 12:03:35
|
New issue 3974: Inconsistent session state after raising exception in after_commit event https://bitbucket.org/zzzeek/sqlalchemy/issues/3974/inconsistent-session-state-after-raising Oleg Lomaka: If you raise an exception in after_commit event handler, then session.is_active is False, but if you try to call session.begin(), you will get an error: "This session is in 'committed' state; no further SQL can be emitted within this transaction." session.begin() will work only after manually calling session.close(). I am not sure is it ok to call close in this case. And not sure you consider this as actually a bug, but apparently the session is in some inconsistent state after raising exception in after_commit event handler. ``` #!python @event.listens_for(session, 'after_commit') def handler(session): raise Exception try: with session.begin(): pass except Exception as e: pass session.begin() # raises "This session is in 'committed' state; no further SQL can be emitted within this transaction." ``` |