]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
allow rollback within _prepare_impl on twophase prepare failure
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 9 Jun 2026 18:47:46 +0000 (14:47 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 9 Jun 2026 18:48:24 +0000 (14:48 -0400)
commitb48c29ea5217651896f3c64408f1655df5bd3a8d
tree163d129374aa0703dd607ff233bd1099027a3821
parenta373a27e4c3d2b8851fcf36871eee96c03d73414
allow rollback within _prepare_impl on twophase prepare failure

When tpc_prepare() raised during SessionTransaction._prepare_impl(),
the error handler's call to self.rollback() was blocked by the
@declare_states decorator, which had set _next_state to
CHANGE_IN_PROGRESS. This caused IllegalStateChangeError to be raised
instead of the original database exception, masking the real error
and preventing proper cleanup.

Used _expect_state(SessionTransactionState.CLOSED) to temporarily
allow the rollback state transition, matching the existing pattern
used in commit() for the close() call.

Fixes: #13356
Change-Id: Ie8212d5b6f8515340cf9d83c56dcbfa5a7415812
(cherry picked from commit 30d75f9a30beab059b6ce93d2c200fd8944d0eb9)
doc/build/changelog/unreleased_20/13356.rst [new file with mode: 0644]
lib/sqlalchemy/orm/session.py
test/orm/test_transaction.py