-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
future engine does not close connection on failed begin #7272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
although at the same time the future context manager is acting like the asyncio one where it doesnt begin until you enter it. this is also wrong for a sync context manager. begin() should begin() the transaction, just like the old one. |
the sessionmaker().begin() context manager does not evaluate the begin() until entered. need to see if there is some precedent on this. |
here's the official "begin a transaction" example in pep 343: from contextlib import contextmanager
from unittest import mock
@contextmanager
def transaction(db):
db.begin()
try:
yield None
except:
db.rollback()
raise
else:
db.commit()
m1 = mock.Mock()
transaction(m1)
assert m1.mock_calls == []
with transaction(m1):
pass
assert m1.mock_calls == [mock.call.begin(), mock.call.commit()] above, db.begin() is not called until the context manager is entered. |
Mike Bayer has proposed a fix for this issue in the main branch: use full context manager flow for future.Engine.begin() https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3252 |
Mike Bayer has proposed a fix for this issue in the rel_1_4 branch: use full context manager flow for future.Engine.begin() https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3253 |
Fixed issue in future :class:`_future.Engine` where calling upon :meth:`_future.Engine.begin` and entering the context manager would not close the connection if the actual BEGIN operation failed for some reason, such as an event handler raising an exception; this use case failed to be tested for the future version of the engine. Note that the "future" context managers which handle ``begin()`` blocks in Core and ORM don't actually run the "BEGIN" operation until the context managers are actually entered. This is different from the legacy version which runs the "BEGIN" operation up front. Fixes: #7272 Change-Id: I9667ac0861a9e007c4b3dfcf0fcf0829038a8711 (cherry picked from commit c4abf5a)
this test didnt get set up in test_execute
if begin fails, the connection stays opened, fix:
The text was updated successfully, but these errors were encountered: