From 666843d320315d2fd2b5c4129b929af20669008d Mon Sep 17 00:00:00 2001 From: Mark Keller <63477823+sfc-gh-mkeller@users.noreply.github.com> Date: Mon, 5 Oct 2020 19:54:17 +0000 Subject: [PATCH] Release 1.2.4 (#195) Co-authored-by: ankit-bhatnagar167 --- DESCRIPTION.rst | 4 ++++ __init__.py | 3 +-- setup.py | 2 +- snowdialect.py | 6 +++--- test/conftest.py | 6 +++--- test/test_core.py | 34 +++++++++++++++++++++++++++++++--- test/test_unit_cte.py | 4 +--- version.py | 2 +- 8 files changed, 45 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION.rst b/DESCRIPTION.rst index d1487931..a99066f7 100644 --- a/DESCRIPTION.rst +++ b/DESCRIPTION.rst @@ -10,6 +10,10 @@ https://github.com/snowflakedb/snowflake-sqlalchemy Release Notes ------------------------------------------------------------------------------- +- v1.2.4 (October 05,2020) + + - Fixed an issue where inspector would not properly switch to table wide column retrieving when schema wide column retrieving was taking too long to respond. + - v1.2.3 (March 30, 2020) - Update tox.ini diff --git a/__init__.py b/__init__.py index d34b7b89..304af229 100644 --- a/__init__.py +++ b/__init__.py @@ -18,7 +18,6 @@ ) from .util import _url as URL from .version import VERSION -from snowflake.connector.compat import TO_UNICODE from sqlalchemy.types import ( BIGINT, BINARY, @@ -55,7 +54,7 @@ VARIANT, ) -SNOWFLAKE_CONNECTOR_VERSION = '.'.join(TO_UNICODE(v) for v in VERSION[0:3]) +SNOWFLAKE_CONNECTOR_VERSION = '.'.join(str(v) for v in VERSION[0:3]) base.dialect = dialect = snowdialect.dialect diff --git a/setup.py b/setup.py index aa371e4d..9e12fe48 100644 --- a/setup.py +++ b/setup.py @@ -83,7 +83,7 @@ ], extras_require={ 'development': [ - 'pytest', + 'pytest<6.1.0', 'pytest-cov', 'pytest-rerunfailures', 'pytest-timeout', diff --git a/snowdialect.py b/snowdialect.py index 511be319..2d744371 100644 --- a/snowdialect.py +++ b/snowdialect.py @@ -324,8 +324,8 @@ def _get_schema_columns(self, connection, schema, **kw): ans = {} current_database, _ = self._current_database_schema(connection, **kw) full_schema_name = self._denormalize_quote_join(current_database, schema) - schema_primary_keys = self._get_schema_primary_keys(connection, full_schema_name, **kw) try: + schema_primary_keys = self._get_schema_primary_keys(connection, full_schema_name, **kw) result = connection.execute(""" SELECT /* sqlalchemy:_get_schema_columns */ ic.table_name, @@ -341,8 +341,8 @@ def _get_schema_columns(self, connection, schema, **kw): FROM information_schema.columns ic WHERE ic.table_schema=%(table_schema)s ORDER BY ic.ordinal_position""", {"table_schema": self.denormalize_name(schema)}) - except ProgrammingError as pe: - if pe.errno == 90030: + except sa_exc.ProgrammingError as pe: + if pe.orig.errno == 90030: # This means that there are too many tables in the schema, we need to go more granular return None # None triggers _get_table_columns while staying cacheable raise diff --git a/test/conftest.py b/test/conftest.py index 11720bbc..6bca1e13 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -13,7 +13,7 @@ import pytest import snowflake.connector from parameters import CONNECTION_PARAMETERS -from snowflake.connector.compat import IS_WINDOWS, TO_UNICODE +from snowflake.connector.compat import IS_WINDOWS from snowflake.sqlalchemy import URL, dialect from sqlalchemy import create_engine @@ -21,7 +21,7 @@ TEST_SCHEMA = 'TRAVIS_JOB_{0}'.format(os.getenv('TRAVIS_JOB_ID')) else: TEST_SCHEMA = ( - 'sqlalchemy_tests_' + TO_UNICODE(uuid.uuid4()).replace('-', '_')) + 'sqlalchemy_tests_' + str(uuid.uuid4()).replace('-', '_')) @pytest.fixture(scope='session') @@ -95,7 +95,7 @@ def get_db_parameters(): # a unique table name ret['name'] = ( 'sqlalchemy_tests_' + - TO_UNICODE(uuid.uuid4())).replace('-', '_') + str(uuid.uuid4())).replace('-', '_') ret['schema'] = TEST_SCHEMA # This reduces a chance to exposing password in test output. diff --git a/test/test_core.py b/test/test_core.py index 1a2fd909..b990ff11 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -12,8 +12,10 @@ import pytest from conftest import get_engine from mock import patch +from sqlalchemy.exc import DBAPIError + from parameters import CONNECTION_PARAMETERS -from snowflake.connector import ProgrammingError, connect +from snowflake.connector import ProgrammingError, connect, Error from snowflake.sqlalchemy import URL, MergeInto, dialect from sqlalchemy import ( REAL, @@ -35,6 +37,8 @@ ) from sqlalchemy.sql import and_, not_, or_, select +from snowflake.sqlalchemy.snowdialect import SnowflakeDialect + try: from parameters import (CONNECTION_PARAMETERS2) except ImportError: @@ -1233,8 +1237,32 @@ def test_too_many_columns_detection(engine_testaccount, db_parameters): def mock_helper(command, *args, **kwargs): if '_get_schema_columns' in command: - raise ProgrammingError("Information schema query returned too much data. Please repeat query with more " - "selective predicates.", 90030) + # Creating exception exactly how SQLAlchemy does + raise DBAPIError.instance( + ''' + SELECT /* sqlalchemy:_get_schema_columns */ + ic.table_name, + ic.column_name, + ic.data_type, + ic.character_maximum_length, + ic.numeric_precision, + ic.numeric_scale, + ic.is_nullable, + ic.column_default, + ic.is_identity, + ic.comment + FROM information_schema.columns ic + WHERE ic.table_schema='schema_name' + ORDER BY ic.ordinal_position''', + {'table_schema': 'TESTSCHEMA'}, + ProgrammingError("Information schema query returned too much data. Please repeat query with more " + "selective predicates.", 90030), + Error, + hide_parameters=False, + connection_invalidated=False, + dialect=SnowflakeDialect(), + ismulti=None + ) else: return original_execute(command, *args, **kwargs) diff --git a/test/test_unit_cte.py b/test/test_unit_cte.py index 8462e381..ec67fe63 100644 --- a/test/test_unit_cte.py +++ b/test/test_unit_cte.py @@ -4,8 +4,6 @@ # Copyright (c) 2012-2019 Snowflake Computing Inc. All right reserved. # -from snowflake.connector.compat import TO_UNICODE - def test_cte(): from snowflake.sqlalchemy import snowdialect @@ -21,7 +19,7 @@ def test_cte(): with_bar = select([literal(product_id), literal(day), literal(count)]).cte('bar') sel = select([with_bar]) ins = visitors.insert().from_select([visitors.c.product_id, visitors.c.date1, visitors.c.count], sel) - assert TO_UNICODE(ins.compile(dialect=snowdialect.dialect())) == ( + assert str(ins.compile(dialect=snowdialect.dialect())) == ( "INSERT INTO visitors (product_id, date1, count) WITH bar AS \n" "(SELECT %(param_1)s AS anon_1, %(param_2)s AS anon_2, %(param_3)s AS anon_3)\n" " SELECT bar.anon_1, bar.anon_2, bar.anon_3 \n" diff --git a/version.py b/version.py index 565c595d..228e1dff 100644 --- a/version.py +++ b/version.py @@ -1,3 +1,3 @@ # Update this for the versions # Don't change the forth version number from None -VERSION = (1, 2, 3, None) +VERSION = (1, 2, 4, None)