summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-04-21 14:44:45 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-04-21 22:31:42 -0400
commit37414a752b0036334d0f31ac8cd3aff749c3898b (patch)
treee36b3980321484362c4b679caa70ddc464324f43 /lib/sqlalchemy/testing
parented3f2c617239668d74ad3d86aeda0ca2030a5933 (diff)
downloadsqlalchemy-37414a752b0036334d0f31ac8cd3aff749c3898b.tar.gz
Add new "sync once" mode for pool.connect
Fixed critical regression caused by the change in :ticket`5497` where the connection pool "init" phase no longer occurred within mutexed isolation, allowing other threads to proceed with the dialect uninitialized, which could then impact the compilation of SQL statements. This issue is essentially the same regression which was fixed many years ago in :ticket:`2964` in dd32540dabbee0678530fb1b0868d1eb41572dca, which was missed this time as the test suite fo that issue only tested the pool in isolation, and assumed the "first_connect" event would be used by the Engine. However :ticket:`5497` stopped using "first_connect" and no test detected the lack of mutexing, that has been resolved here through the addition of more tests. This fix also identifies what is probably a bug in earlier versions of SQLAlchemy where the "first_connect" handler would be cancelled if the initializer failed; this is evidenced by test_explode_in_initializer which was doing a reconnect due to c.rollback() yet wasn't hanging. We now solve this issue by preventing the manufactured Connection from ever reconnecting inside the first_connect handler. Also remove the "_sqla_unwrap" test attribute; this is almost not used anymore however we can use a more targeted wrapper supplied by the testing.engines.proxying_engine function. See if we can also open up Oracle for "ad hoc engines" tests now that we have better connection management logic. Fixes: #6337 Change-Id: I4a3476625c4606f1a304dbc940d500325e8adc1a
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/engines.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/sqlalchemy/testing/engines.py b/lib/sqlalchemy/testing/engines.py
index 3faf96857..1d740b4f3 100644
--- a/lib/sqlalchemy/testing/engines.py
+++ b/lib/sqlalchemy/testing/engines.py
@@ -405,7 +405,7 @@ class DBAPIProxyConnection(object):
"""
def __init__(self, engine, cursor_cls):
- self.conn = self._sqla_unwrap = engine.pool._creator()
+ self.conn = engine.pool._creator()
self.engine = engine
self.cursor_cls = cursor_cls
@@ -430,4 +430,15 @@ def proxying_engine(
def mock_conn():
return conn_cls(config.db, cursor_cls)
- return testing_engine(options={"creator": mock_conn})
+ def _wrap_do_on_connect(do_on_connect):
+ def go(dbapi_conn):
+ return do_on_connect(dbapi_conn.conn)
+
+ return go
+
+ return testing_engine(
+ options={
+ "creator": mock_conn,
+ "_wrap_do_on_connect": _wrap_do_on_connect,
+ }
+ )