]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Support "sqlalchemy.future" for engine_from_config
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 6 Nov 2020 20:44:39 +0000 (15:44 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 6 Nov 2020 20:45:30 +0000 (15:45 -0500)
Added the "future" keyword to the list of words that are known by the
:func:`_sa.engine_from_config` function, so that the values "true" and
"false" may be configured as "boolean" values when using a key such
as ``sqlalchemy.future = true`` or ``sqlalchemy.future = false``.

Change-Id: Ib4bba748497cc68e4c913dde54c23a4bb08b4deb

doc/build/changelog/unreleased_14/engfconfig.rst [new file with mode: 0644]
lib/sqlalchemy/engine/create.py
lib/sqlalchemy/engine/default.py
test/engine/test_parseconnect.py

diff --git a/doc/build/changelog/unreleased_14/engfconfig.rst b/doc/build/changelog/unreleased_14/engfconfig.rst
new file mode 100644 (file)
index 0000000..4ffa78a
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: bug, engine
+
+    Added the "future" keyword to the list of words that are known by the
+    :func:`_sa.engine_from_config` function, so that the values "true" and
+    "false" may be configured as "boolean" values when using a key such
+    as ``sqlalchemy.future = true`` or ``sqlalchemy.future = false``.
+
index 4d84687ea323d08ab1457f89287db7bd5cb9c071..7f5b5e8f5deb6054cc0beac5ee2b5a1702c7c8e6 100644 (file)
@@ -601,7 +601,7 @@ def create_engine(url, **kwargs):
         pool._dialect = dialect
 
     # create engine.
-    if kwargs.pop("future", False):
+    if pop_kwarg("future", False):
         from sqlalchemy import future
 
         default_engine_class = future.Engine
index 7f92271e97c0bd2ffb1af3cb44a184df48a558b5..59a4b47dc07e521ed593bc9abc467046c183b654 100644 (file)
@@ -98,6 +98,7 @@ class DefaultDialect(interfaces.Dialect):
             ("pool_recycle", util.asint),
             ("pool_size", util.asint),
             ("max_overflow", util.asint),
+            ("future", util.asbool),
         ]
     )
 
index b39d5f8add8cc30e631d0d7e246ff477421b1f45..22853cf376d780aff0db9dfe1b5dcf9f425a5e4e 100644 (file)
@@ -394,6 +394,30 @@ class CreateEngineTest(fixtures.TestBase):
         )
         assert e.echo is True
 
+    def test_engine_from_config_future(self):
+        dbapi = mock_dbapi
+
+        config = {
+            "sqlalchemy.url": "postgresql://scott:tiger@somehost/test"
+            "?fooz=somevalue",
+            "sqlalchemy.future": "true",
+        }
+
+        e = engine_from_config(config, module=dbapi, _initialize=False)
+        assert e._is_future
+
+    def test_engine_from_config_not_future(self):
+        dbapi = mock_dbapi
+
+        config = {
+            "sqlalchemy.url": "postgresql://scott:tiger@somehost/test"
+            "?fooz=somevalue",
+            "sqlalchemy.future": "false",
+        }
+
+        e = engine_from_config(config, module=dbapi, _initialize=False)
+        assert not e._is_future
+
     def test_pool_reset_on_return_from_config(self):
         dbapi = mock_dbapi