From: Mike Bayer Date: Tue, 26 May 2015 14:56:23 +0000 (-0400) Subject: - Fixed bug where known boolean values used by X-Git-Tag: rel_1_0_5~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a50dcb31b9757ca7602b85458615b7c267454cf9;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug where known boolean values used by :func:`.engine_from_config` were not being parsed correctly; these included ``pool_threadlocal`` and the psycopg2 argument ``use_native_unicode``. fixes #3435 - add legacy_schema_aliasing config parsing for mssql - move use_native_unicode config arg to the psycopg2 dialect --- diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index 2ed4f85513..038b5b4da1 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -18,6 +18,15 @@ .. changelog:: :version: 1.0.5 + .. change:: + :tags: bug, engine + :tickets: 3435 + + Fixed bug where known boolean values used by + :func:`.engine_from_config` were not being parsed correctly; + these included ``pool_threadlocal`` and the psycopg2 argument + ``use_native_unicode``. + .. change:: :tags: bug, mssql :tickets: 3424, 3430 diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index d61ab19583..928953126b 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -1494,6 +1494,10 @@ class MSDialect(default.DefaultDialect): sqltypes.Time: TIME, } + engine_config_types = default.DefaultDialect.engine_config_types.union([ + ('legacy_schema_aliasing', util.asbool), + ]) + ischema_names = ischema_names supports_native_boolean = False diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index f66ba9693b..f83bab2fab 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -505,6 +505,10 @@ class PGDialect_psycopg2(PGDialect): _has_native_json = False _has_native_jsonb = False + engine_config_types = PGDialect.engine_config_types.union([ + ('use_native_unicode', util.asbool), + ]) + colspecs = util.update_copy( PGDialect.colspecs, { diff --git a/lib/sqlalchemy/engine/__init__.py b/lib/sqlalchemy/engine/__init__.py index 0678dd201c..f1eacf6a6e 100644 --- a/lib/sqlalchemy/engine/__init__.py +++ b/lib/sqlalchemy/engine/__init__.py @@ -394,9 +394,9 @@ def engine_from_config(configuration, prefix='sqlalchemy.', **kwargs): 'prefix' argument indicates the prefix to be searched for. A select set of keyword arguments will be "coerced" to their - expected type based on string values. In a future release, this - functionality will be expanded and include dialect-specific - arguments. + expected type based on string values. The set of arguments + is extensible per-dialect using the ``engine_config_types`` accessor. + """ options = dict((key[len(prefix):], configuration[key]) diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 9330a602c1..9a7b80bfdc 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -61,14 +61,13 @@ class DefaultDialect(interfaces.Dialect): engine_config_types = util.immutabledict([ ('convert_unicode', util.bool_or_str('force')), - ('pool_timeout', int), + ('pool_timeout', util.asint), ('echo', util.bool_or_str('debug')), ('echo_pool', util.bool_or_str('debug')), - ('pool_recycle', int), - ('pool_size', int), - ('max_overflow', int), - ('pool_threadlocal', bool), - ('use_native_unicode', bool), + ('pool_recycle', util.asint), + ('pool_size', util.asint), + ('max_overflow', util.asint), + ('pool_threadlocal', util.asbool), ]) # if the NUMERIC type diff --git a/test/dialect/mssql/test_engine.py b/test/dialect/mssql/test_engine.py index a994b17875..26f2d4ce92 100644 --- a/test/dialect/mssql/test_engine.py +++ b/test/dialect/mssql/test_engine.py @@ -170,6 +170,16 @@ class ParseConnectTest(fixtures.TestBase): engine.connect) +class EngineFromConfigTest(fixtures.TestBase): + def test_legacy_schema_flag(self): + cfg = { + "sqlalchemy.url": "mssql://foodsn", + "sqlalchemy.legacy_schema_aliasing": "false" + } + e = engine_from_config(cfg) + eq_(e.dialect.legacy_schema_aliasing, False) + + class VersionDetectionTest(fixtures.TestBase): def test_pymssql_version(self): dialect = pymssql.MSDialect_pymssql() diff --git a/test/dialect/postgresql/test_dialect.py b/test/dialect/postgresql/test_dialect.py index bdd292fff6..5d74d54ad6 100644 --- a/test/dialect/postgresql/test_dialect.py +++ b/test/dialect/postgresql/test_dialect.py @@ -14,6 +14,7 @@ from sqlalchemy.dialects.postgresql import base as postgresql import logging import logging.handlers from sqlalchemy.testing.mock import Mock +from sqlalchemy.engine import engine_from_config class MiscTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): @@ -120,6 +121,22 @@ class MiscTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): new_encoding = c.execute("show client_encoding").fetchone()[0] eq_(new_encoding, test_encoding) + def test_pg_dialect_use_native_unicode_from_config(self): + config = { + 'sqlalchemy.url': 'postgresql://scott:tiger@somehost/test', + 'sqlalchemy.use_native_unicode': "false"} + + e = engine_from_config(config, _initialize=False) + eq_(e.dialect.use_native_unicode, False) + + config = { + 'sqlalchemy.url': 'postgresql://scott:tiger@somehost/test', + 'sqlalchemy.use_native_unicode': "true"} + + e = engine_from_config(config, _initialize=False) + eq_(e.dialect.use_native_unicode, True) + + @testing.only_on( ['postgresql+psycopg2', 'postgresql+pg8000', 'postgresql+psycopg2cffi'], diff --git a/test/engine/test_parseconnect.py b/test/engine/test_parseconnect.py index fb1f338e65..4601a6bda1 100644 --- a/test/engine/test_parseconnect.py +++ b/test/engine/test_parseconnect.py @@ -138,6 +138,23 @@ class CreateEngineTest(fixtures.TestBase): 'z=somevalue') assert e.echo is True + def test_pool_threadlocal_from_config(self): + dbapi = mock_dbapi + + config = { + 'sqlalchemy.url': 'postgresql://scott:tiger@somehost/test', + 'sqlalchemy.pool_threadlocal': "false"} + + e = engine_from_config(config, module=dbapi, _initialize=False) + eq_(e.pool._use_threadlocal, False) + + config = { + 'sqlalchemy.url': 'postgresql://scott:tiger@somehost/test', + 'sqlalchemy.pool_threadlocal': "true"} + + e = engine_from_config(config, module=dbapi, _initialize=False) + eq_(e.pool._use_threadlocal, True) + def test_pool_reset_on_return_from_config(self): dbapi = mock_dbapi