summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/create.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-08-07 14:51:33 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-08-07 18:01:49 -0400
commit302e8dee82718df6c3a46de4c5283bdae51a650a (patch)
tree0df6953aba01b6ff72a7094ff0887d11c4a700f0 /lib/sqlalchemy/engine/create.py
parent40d64f3a525b14272b7354c72d7f84f6b00796f9 (diff)
downloadsqlalchemy-302e8dee82718df6c3a46de4c5283bdae51a650a.tar.gz
Don't link on_connect to first_connect event handler
Adjusted the dialect initialization process such that the :meth:`_engine.Dialect.on_connect` is not called a second time on the first connection. The hook is called first, then the :meth:`_engine.Dialect.initialize` is called if that connection is the first for that dialect, then no more events are called. This eliminates the two calls to the "on_connect" function which can produce very difficult debugging situations. Fixes: #5497 Change-Id: Icefc2e884e30ee7b4ac84b99dc54bf992a6085e3
Diffstat (limited to 'lib/sqlalchemy/engine/create.py')
-rw-r--r--lib/sqlalchemy/engine/create.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/sqlalchemy/engine/create.py b/lib/sqlalchemy/engine/create.py
index 985a12fa0..dc895ee15 100644
--- a/lib/sqlalchemy/engine/create.py
+++ b/lib/sqlalchemy/engine/create.py
@@ -627,9 +627,9 @@ def create_engine(url, **kwargs):
)
if conn is None:
return
+
do_on_connect(conn)
- event.listen(pool, "first_connect", on_connect)
event.listen(pool, "connect", on_connect)
def first_connect(dbapi_connection, connection_record):
@@ -640,9 +640,17 @@ def create_engine(url, **kwargs):
dialect.initialize(c)
dialect.do_rollback(c.connection)
- event.listen(
- pool, "first_connect", first_connect, _once_unless_exception=True
- )
+ if do_on_connect:
+ event.listen(
+ pool, "connect", first_connect, _once_unless_exception=True
+ )
+ else:
+ event.listen(
+ pool,
+ "first_connect",
+ first_connect,
+ _once_unless_exception=True,
+ )
dialect_cls.engine_created(engine)
if entrypoint is not dialect_cls: