]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
unify transactional context managers
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 2 May 2021 22:31:03 +0000 (18:31 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 6 May 2021 02:21:07 +0000 (22:21 -0400)
commitc5587fda7986df5851491a069830ddd4a63e01ba
tree3cbc7f7eb5a1c477032e20ace015a7502d5c2823
parentee7a82d71783bf71f3a95550624740e908d178a0
unify transactional context managers

Applied consistent behavior to the use case of
calling ``.commit()`` or ``.rollback()`` inside of an existing
``.begin()`` context manager, with the addition of potentially
emitting SQL within the block subsequent to the commit or rollback.
This change continues upon the change first added in
:ticket:`6155` where the use case of calling "rollback" inside of
a ``.begin()`` contextmanager block was proposed:

* calling ``.commit()`` or ``.rollback()`` will now be allowed
without error or warning within all scopes, including
that of legacy and future :class:`_engine.Engine`, ORM
:class:`_orm.Session`, asyncio :class:`.AsyncEngine`.  Previously,
the :class:`_orm.Session` disallowed this.

* The remaining scope of the context manager is then closed;
when the block ends, a check is emitted to see if the transaction
was already ended, and if so the block returns without action.

* It will now raise **an error** if subsequent SQL of any kind
is emitted within the block, **after** ``.commit()`` or
``.rollback()`` is called.   The block should be closed as
the state of the executable object would otherwise be undefined
in this state.

Fixes: #6288
Change-Id: I8b21766ae430f0fa1ac5ef689f4c0fb19fc84336
14 files changed:
doc/build/changelog/unreleased_14/6288.rst [new file with mode: 0644]
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/engine/util.py
lib/sqlalchemy/ext/asyncio/base.py
lib/sqlalchemy/ext/asyncio/engine.py
lib/sqlalchemy/ext/asyncio/session.py
lib/sqlalchemy/future/engine.py
lib/sqlalchemy/orm/session.py
lib/sqlalchemy/testing/fixtures.py
lib/sqlalchemy/util/concurrency.py
test/engine/test_transaction.py
test/ext/asyncio/test_engine_py3k.py
test/ext/asyncio/test_session_py3k.py
test/orm/test_transaction.py