]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
ensure db_opts are honored
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 9 Dec 2024 17:36:56 +0000 (12:36 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 9 Dec 2024 17:41:45 +0000 (12:41 -0500)
for provision.py that adds db_opts these need to be used in all cases
for testing_engine() that is using that same database driver

References: #12159
Change-Id: I15c46a375ab05ef94c9a7d19000a3d8641de43bf
(cherry picked from commit 3226f99dce77bb75698a7c9366f6fd07ab4d29ee)

lib/sqlalchemy/testing/engines.py

index 7cae807eb43b7112769e2ec277a5a97444a9ef1a..08fbe248e15e189b7acbafda7acead7d3ed38019 100644 (file)
@@ -330,16 +330,18 @@ def testing_engine(
     url = url or config.db.url
 
     url = make_url(url)
-    if options is None:
-        if config.db is None or url.drivername == config.db.url.drivername:
-            options = config.db_opts
-        else:
-            options = {}
-    elif config.db is not None and url.drivername == config.db.url.drivername:
-        default_opt = config.db_opts.copy()
-        default_opt.update(options)
 
-    engine = create_engine(url, **options)
+    if (
+        config.db is None or url.drivername == config.db.url.drivername
+    ) and config.db_opts:
+        use_options = config.db_opts.copy()
+    else:
+        use_options = {}
+
+    if options is not None:
+        use_options.update(options)
+
+    engine = create_engine(url, **use_options)
 
     if sqlite_savepoint and engine.name == "sqlite":
         # apply SQLite savepoint workaround
@@ -370,9 +372,9 @@ def testing_engine(
 
     if (
         isinstance(engine.pool, pool.QueuePool)
-        and "pool" not in options
-        and "pool_timeout" not in options
-        and "max_overflow" not in options
+        and "pool" not in use_options
+        and "pool_timeout" not in use_options
+        and "max_overflow" not in use_options
     ):
         engine.pool._timeout = 0
         engine.pool._max_overflow = 0