From: Mike Bayer Date: Fri, 6 Nov 2020 20:44:39 +0000 (-0500) Subject: Support "sqlalchemy.future" for engine_from_config X-Git-Tag: rel_1_4_0b2~168 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5ed0f5d6e0526a4ee2f9f164b7da79de11a481e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Support "sqlalchemy.future" for engine_from_config 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 --- diff --git a/doc/build/changelog/unreleased_14/engfconfig.rst b/doc/build/changelog/unreleased_14/engfconfig.rst new file mode 100644 index 0000000000..4ffa78ae7f --- /dev/null +++ b/doc/build/changelog/unreleased_14/engfconfig.rst @@ -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``. + diff --git a/lib/sqlalchemy/engine/create.py b/lib/sqlalchemy/engine/create.py index 4d84687ea3..7f5b5e8f5d 100644 --- a/lib/sqlalchemy/engine/create.py +++ b/lib/sqlalchemy/engine/create.py @@ -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 diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 7f92271e97..59a4b47dc0 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -98,6 +98,7 @@ class DefaultDialect(interfaces.Dialect): ("pool_recycle", util.asint), ("pool_size", util.asint), ("max_overflow", util.asint), + ("future", util.asbool), ] ) diff --git a/test/engine/test_parseconnect.py b/test/engine/test_parseconnect.py index b39d5f8add..22853cf376 100644 --- a/test/engine/test_parseconnect.py +++ b/test/engine/test_parseconnect.py @@ -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