Skip to content

Commit ab1bd05

Browse files
authored
SNOW-716374: reapply telemetry change of application and test panda arrow result format (#370)
1 parent 13f543d commit ab1bd05

File tree

10 files changed

+159
-38
lines changed

10 files changed

+159
-38
lines changed

.github/workflows/build_test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ jobs:
9898
.tox/coverage.xml
9999
100100
test_connector_regression:
101-
if: ${{ false }} # disable temporarily
102101
name: Connector Regression Test ${{ matrix.os.download_name }}-${{ matrix.python-version }}-${{ matrix.cloud-provider }}
103102
needs: lint
104103
runs-on: ${{ matrix.os.image_name }}
@@ -142,7 +141,7 @@ jobs:
142141
combine-coverage:
143142
if: ${{ success() || failure() }}
144143
name: Combine coverage
145-
needs: [test]
144+
needs: [test, test_connector_regression]
146145
runs-on: ubuntu-latest
147146
steps:
148147
- uses: actions/checkout@v2

DESCRIPTION.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ Source code is also available at:
99

1010
# Release Notes
1111

12+
- v1.4.7(Unreleased)
13+
14+
- Re-applied the application name of driver connection `SnowflakeConnection` to `SnowflakeSQLAlchemy`.
15+
1216
- v1.4.6(Feb 8, 2023)
1317

14-
- Bumped snowflake-connector-python dependency to newest version which supports Python 3.11.
15-
- Reverted the change of application name introduced in v1.4.5 until support gets added.
18+
- Bumped snowflake-connector-python dependency to newest version which supports Python 3.11.
19+
- Reverted the change of application name introduced in v1.4.5 until support gets added.
1620

1721
- v1.4.5(Dec 7, 2022)
1822

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ universal = 1
33

44
[metadata]
55
name = snowflake-sqlalchemy
6-
version = 1.4.6
76
description = Snowflake SQLAlchemy Dialect
87
long_description = file: DESCRIPTION.md
98
long_description_content_type = text/markdown

setup.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
# Copyright (c) 2012-2022 Snowflake Computing Inc. All rights reserved.
33
#
44

5+
import os
6+
57
from setuptools import setup
68

7-
setup()
9+
SQLALCHEMY_SRC_DIR = os.path.join("src", "snowflake", "sqlalchemy")
10+
VERSION = (1, 1, 1, None) # Default
11+
with open(os.path.join(SQLALCHEMY_SRC_DIR, "version.py"), encoding="utf-8") as f:
12+
exec(f.read())
13+
version = ".".join([str(v) for v in VERSION if v is not None])
14+
15+
setup(
16+
version=version,
17+
)
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#
22
# Copyright (c) 2012-2022 Snowflake Computing Inc. All rights reserved.
33
#
4-
import pkg_resources
4+
from .version import VERSION
55

66
# parameters needed for usage tracking
77
PARAM_APPLICATION = "application"
88
PARAM_INTERNAL_APPLICATION_NAME = "internal_application_name"
99
PARAM_INTERNAL_APPLICATION_VERSION = "internal_application_version"
1010

1111
APPLICATION_NAME = "SnowflakeSQLAlchemy"
12-
SNOWFLAKE_SQLALCHEMY_VERSION = pkg_resources.get_distribution(
13-
"snowflake-sqlalchemy"
14-
).version
12+
SNOWFLAKE_SQLALCHEMY_VERSION = ".".join([str(v) for v in VERSION if v is not None])

src/snowflake/sqlalchemy/snowdialect.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
_CUSTOM_Float,
6262
_CUSTOM_Time,
6363
)
64+
from .util import _update_connection_application_name
6465

6566
colspecs = {
6667
Date: _CUSTOM_Date,
@@ -107,6 +108,9 @@
107108
}
108109

109110

111+
_ENABLE_SQLALCHEMY_AS_APPLICATION_NAME = True
112+
113+
110114
class SnowflakeDialect(default.DefaultDialect):
111115
name = "snowflake"
112116
driver = "snowflake"
@@ -834,6 +838,18 @@ def get_table_comment(self, connection, table_name, schema=None, **kw):
834838
else None
835839
}
836840

841+
def connect(self, *cargs, **cparams):
842+
return (
843+
super().connect(
844+
*cargs,
845+
**_update_connection_application_name(**cparams)
846+
if _ENABLE_SQLALCHEMY_AS_APPLICATION_NAME
847+
else cparams,
848+
)
849+
if _ENABLE_SQLALCHEMY_AS_APPLICATION_NAME
850+
else super().connect(*cargs, **cparams)
851+
)
852+
837853

838854
@sa_vnt.listens_for(Table, "before_create")
839855
def check_table(table, connection, _ddl_runner, **kw):

src/snowflake/sqlalchemy/version.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Copyright (c) 2012-2022 Snowflake Computing Inc. All rights reserved.
3+
#
4+
# Update this for the versions
5+
# Don't change the forth version number from None
6+
VERSION = (1, 4, 7, None)

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@
1313
from sqlalchemy import create_engine
1414

1515
import snowflake.connector
16+
import snowflake.connector.connection
1617
from snowflake.connector.compat import IS_WINDOWS
1718
from snowflake.sqlalchemy import URL, dialect
19+
from snowflake.sqlalchemy._constants import (
20+
APPLICATION_NAME,
21+
PARAM_APPLICATION,
22+
PARAM_INTERNAL_APPLICATION_NAME,
23+
PARAM_INTERNAL_APPLICATION_VERSION,
24+
SNOWFLAKE_SQLALCHEMY_VERSION,
25+
)
1826

1927
from .parameters import CONNECTION_PARAMETERS
2028

@@ -23,6 +31,17 @@
2331
INTERNAL_SKIP_TAGS = {"external"}
2432
RUNNING_ON_GH = os.getenv("GITHUB_ACTIONS") == "true"
2533

34+
snowflake.connector.connection.DEFAULT_CONFIGURATION[PARAM_APPLICATION] = (
35+
APPLICATION_NAME,
36+
(type(None), str),
37+
)
38+
snowflake.connector.connection.DEFAULT_CONFIGURATION[
39+
PARAM_INTERNAL_APPLICATION_NAME
40+
] = (APPLICATION_NAME, (type(None), str))
41+
snowflake.connector.connection.DEFAULT_CONFIGURATION[
42+
PARAM_INTERNAL_APPLICATION_VERSION
43+
] = (SNOWFLAKE_SQLALCHEMY_VERSION, (type(None), str))
44+
2645
TEST_SCHEMA = f"sqlalchemy_tests_{str(uuid.uuid4()).replace('-', '_')}"
2746

2847
create_engine_with_future_flag = create_engine

tests/connector_regression

Submodule connector_regression updated 62 files

tests/test_core.py

Lines changed: 97 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
from sqlalchemy.pool import NullPool
3737
from sqlalchemy.sql import and_, not_, or_, select
3838

39+
import snowflake.connector.errors
40+
import snowflake.sqlalchemy.snowdialect
3941
from snowflake.connector import Error, ProgrammingError, connect
4042
from snowflake.sqlalchemy import URL, MergeInto, dialect
4143
from snowflake.sqlalchemy._constants import (
@@ -99,35 +101,22 @@ def _create_users_addresses_tables_without_sequence(engine_testaccount, metadata
99101
return users, addresses
100102

101103

102-
def verify_engine_connection(engine, verify_app_name):
104+
def verify_engine_connection(engine):
103105
with engine.connect() as conn:
104106
results = conn.execute(text("select current_version()")).fetchone()
105-
if verify_app_name:
106-
assert conn.connection.driver_connection.application == APPLICATION_NAME
107-
assert (
108-
conn.connection.driver_connection._internal_application_name
109-
== APPLICATION_NAME
110-
)
111-
assert (
112-
conn.connection.driver_connection._internal_application_version
113-
== SNOWFLAKE_SQLALCHEMY_VERSION
114-
)
107+
assert conn.connection.driver_connection.application == APPLICATION_NAME
108+
assert (
109+
conn.connection.driver_connection._internal_application_name
110+
== APPLICATION_NAME
111+
)
112+
assert (
113+
conn.connection.driver_connection._internal_application_version
114+
== SNOWFLAKE_SQLALCHEMY_VERSION
115+
)
115116
assert results is not None
116117

117118

118-
@pytest.mark.parametrize(
119-
"verify_app_name",
120-
[
121-
False,
122-
pytest.param(
123-
True,
124-
marks=pytest.mark.xfail(
125-
reason="Pending backend service to recognize SnowflakeSQLAlchemy as a valid client app id"
126-
),
127-
),
128-
],
129-
)
130-
def test_connect_args(verify_app_name):
119+
def test_connect_args():
131120
"""
132121
Tests connect string
133122
@@ -148,7 +137,7 @@ def test_connect_args(verify_app_name):
148137
)
149138
)
150139
try:
151-
verify_engine_connection(engine, verify_app_name)
140+
verify_engine_connection(engine)
152141
finally:
153142
engine.dispose()
154143

@@ -163,7 +152,7 @@ def test_connect_args(verify_app_name):
163152
)
164153
)
165154
try:
166-
verify_engine_connection(engine, verify_app_name)
155+
verify_engine_connection(engine)
167156
finally:
168157
engine.dispose()
169158

@@ -179,7 +168,7 @@ def test_connect_args(verify_app_name):
179168
)
180169
)
181170
try:
182-
verify_engine_connection(engine, verify_app_name)
171+
verify_engine_connection(engine)
183172
finally:
184173
engine.dispose()
185174

@@ -1785,3 +1774,84 @@ def test_normalize_and_denormalize_empty_string_column_name(engine_testaccount):
17851774
and columns[0]["name"] == "col"
17861775
and columns[1]["name"] == ""
17871776
)
1777+
1778+
1779+
def test_snowflake_sqlalchemy_as_valid_client_type():
1780+
engine = create_engine(
1781+
URL(
1782+
user=CONNECTION_PARAMETERS["user"],
1783+
password=CONNECTION_PARAMETERS["password"],
1784+
account=CONNECTION_PARAMETERS["account"],
1785+
host=CONNECTION_PARAMETERS["host"],
1786+
port=CONNECTION_PARAMETERS["port"],
1787+
protocol=CONNECTION_PARAMETERS["protocol"],
1788+
),
1789+
connect_args={"internal_application_name": "UnknownClient"},
1790+
)
1791+
with engine.connect() as conn:
1792+
with pytest.raises(snowflake.connector.errors.NotSupportedError):
1793+
conn.exec_driver_sql("select 1").cursor.fetch_pandas_all()
1794+
1795+
engine = create_engine(
1796+
URL(
1797+
user=CONNECTION_PARAMETERS["user"],
1798+
password=CONNECTION_PARAMETERS["password"],
1799+
account=CONNECTION_PARAMETERS["account"],
1800+
host=CONNECTION_PARAMETERS["host"],
1801+
port=CONNECTION_PARAMETERS["port"],
1802+
protocol=CONNECTION_PARAMETERS["protocol"],
1803+
)
1804+
)
1805+
with engine.connect() as conn:
1806+
conn.exec_driver_sql("select 1").cursor.fetch_pandas_all()
1807+
1808+
try:
1809+
snowflake.sqlalchemy.snowdialect._ENABLE_SQLALCHEMY_AS_APPLICATION_NAME = False
1810+
origin_app = snowflake.connector.connection.DEFAULT_CONFIGURATION["application"]
1811+
origin_internal_app_name = snowflake.connector.connection.DEFAULT_CONFIGURATION[
1812+
"internal_application_name"
1813+
]
1814+
origin_internal_app_version = (
1815+
snowflake.connector.connection.DEFAULT_CONFIGURATION[
1816+
"internal_application_version"
1817+
]
1818+
)
1819+
snowflake.connector.connection.DEFAULT_CONFIGURATION["application"] = (
1820+
None,
1821+
(type(None), str),
1822+
)
1823+
snowflake.connector.connection.DEFAULT_CONFIGURATION[
1824+
"internal_application_name"
1825+
] = ("PythonConnector", (type(None), str))
1826+
snowflake.connector.connection.DEFAULT_CONFIGURATION[
1827+
"internal_application_version"
1828+
] = ("3.0.0", (type(None), str))
1829+
engine = create_engine(
1830+
URL(
1831+
user=CONNECTION_PARAMETERS["user"],
1832+
password=CONNECTION_PARAMETERS["password"],
1833+
account=CONNECTION_PARAMETERS["account"],
1834+
host=CONNECTION_PARAMETERS["host"],
1835+
port=CONNECTION_PARAMETERS["port"],
1836+
protocol=CONNECTION_PARAMETERS["protocol"],
1837+
)
1838+
)
1839+
with engine.connect() as conn:
1840+
conn.exec_driver_sql("select 1").cursor.fetch_pandas_all()
1841+
assert (
1842+
conn.connection.driver_connection._internal_application_name
1843+
== "PythonConnector"
1844+
)
1845+
assert (
1846+
conn.connection.driver_connection._internal_application_version
1847+
== "3.0.0"
1848+
)
1849+
finally:
1850+
snowflake.sqlalchemy.snowdialect._ENABLE_SQLALCHEMY_AS_APPLICATION_NAME = True
1851+
snowflake.connector.connection.DEFAULT_CONFIGURATION["application"] = origin_app
1852+
snowflake.connector.connection.DEFAULT_CONFIGURATION[
1853+
"internal_application_name"
1854+
] = origin_internal_app_name
1855+
snowflake.connector.connection.DEFAULT_CONFIGURATION[
1856+
"internal_application_version"
1857+
] = origin_internal_app_version

0 commit comments

Comments
 (0)