Skip to content

Commit ffb507b

Browse files
committed
SNOW-1763960: clean up todos in code base (#2091)
1 parent 91d68eb commit ffb507b

File tree

11 files changed

+40
-72
lines changed

11 files changed

+40
-72
lines changed

src/snowflake/connector/aio/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@
1212
SnowflakeCursor,
1313
DictCursor,
1414
]
15+
16+
17+
async def connect(**kwargs) -> SnowflakeConnection:
18+
conn = SnowflakeConnection(**kwargs)
19+
await conn.connect()
20+
return conn

src/snowflake/connector/aio/_connection.py

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import os
1111
import pathlib
1212
import sys
13-
import traceback
1413
import uuid
1514
from contextlib import suppress
1615
from io import StringIO
@@ -33,7 +32,6 @@
3332
from ..connection import DEFAULT_CONFIGURATION as DEFAULT_CONFIGURATION_SYNC
3433
from ..connection import SnowflakeConnection as SnowflakeConnectionSync
3534
from ..connection import _get_private_bytes_from_file
36-
from ..connection_diagnostic import ConnectionDiagnostic
3735
from ..constants import (
3836
_CONNECTIVITY_ERR_MSG,
3937
ENV_VAR_PARTNER,
@@ -519,7 +517,7 @@ def _init_connection_parameters(
519517
elif is_kwargs_empty:
520518
# connection_name is None and kwargs was empty when called
521519
ret_kwargs = _get_default_connection_params()
522-
self.__set_error_attributes() # TODO: error attributes async?
520+
# TODO: SNOW-1770153 on self.__set_error_attributes()
523521
return ret_kwargs
524522

525523
async def _cancel_query(
@@ -873,42 +871,9 @@ async def connect(self, **kwargs) -> None:
873871
self.__config(**self._conn_parameters)
874872

875873
if self.enable_connection_diag:
876-
exceptions_dict = {}
877-
# TODO: we can make ConnectionDiagnostic async, do we need?
878-
connection_diag = ConnectionDiagnostic(
879-
account=self.account,
880-
host=self.host,
881-
connection_diag_log_path=self.connection_diag_log_path,
882-
connection_diag_allowlist_path=(
883-
self.connection_diag_allowlist_path
884-
if self.connection_diag_allowlist_path is not None
885-
else self.connection_diag_whitelist_path
886-
),
887-
proxy_host=self.proxy_host,
888-
proxy_port=self.proxy_port,
889-
proxy_user=self.proxy_user,
890-
proxy_password=self.proxy_password,
874+
raise NotImplementedError(
875+
"Connection diagnostic is not supported in asyncio"
891876
)
892-
try:
893-
connection_diag.run_test()
894-
await self.__open_connection()
895-
connection_diag.cursor = self.cursor()
896-
except Exception:
897-
exceptions_dict["connection_test"] = traceback.format_exc()
898-
logger.warning(
899-
f"""Exception during connection test:\n{exceptions_dict["connection_test"]} """
900-
)
901-
try:
902-
connection_diag.run_post_test()
903-
except Exception:
904-
exceptions_dict["post_test"] = traceback.format_exc()
905-
logger.warning(
906-
f"""Exception during post connection test:\n{exceptions_dict["post_test"]} """
907-
)
908-
finally:
909-
connection_diag.generate_report()
910-
if exceptions_dict:
911-
raise Exception(str(exceptions_dict))
912877
else:
913878
await self.__open_connection()
914879
self._telemetry = TelemetryClient(self._rest)
@@ -924,7 +889,10 @@ def cursor(
924889
None,
925890
DatabaseError,
926891
{
927-
"msg": "Connection is closed",
892+
"msg": "Connection is closed.\nPlease establish the connection first by "
893+
"explicitly calling `await SnowflakeConnection.connect()` or "
894+
"using an async context manager: `async with SnowflakeConnection() as conn`. "
895+
"\nEnsure the connection is open before attempting any operations.",
928896
"errno": ER_CONNECTION_IS_CLOSED,
929897
"sqlstate": SQLSTATE_CONNECTION_NOT_EXISTS,
930898
},

src/snowflake/connector/aio/_cursor.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ async def execute_async(self, *args: Any, **kwargs: Any) -> dict[str, Any]:
828828

829829
@property
830830
def errorhandler(self):
831-
# check SNOW-1763103
831+
# TODO: SNOW-1763103 for async error handler
832832
raise NotImplementedError(
833833
"Async Snowflake Python Connector does not support errorhandler. "
834834
"Please open a feature request issue in github if your want this feature: "
@@ -837,7 +837,7 @@ def errorhandler(self):
837837

838838
@errorhandler.setter
839839
def errorhandler(self, value):
840-
# check SNOW-1763103
840+
# TODO: SNOW-1763103 for async error handler
841841
raise NotImplementedError(
842842
"Async Snowflake Python Connector does not support errorhandler. "
843843
"Please open a feature request issue in github if your want this feature: "
@@ -987,7 +987,6 @@ async def fetch_pandas_all(self, **kwargs: Any) -> DataFrame:
987987
await self._prefetch_hook()
988988
if self._query_result_format != "arrow":
989989
raise NotSupportedError
990-
# # TODO: async telemetry
991990
await self._log_telemetry_job_data(
992991
TelemetryField.PANDAS_FETCH_ALL, TelemetryData.TRUE
993992
)
@@ -1022,7 +1021,6 @@ async def get_result_batches(self) -> list[ResultBatch] | None:
10221021
"""
10231022
if self._result_set is None:
10241023
return None
1025-
# TODO: async telemetry SNOW-1572217
10261024
await self._log_telemetry_job_data(
10271025
TelemetryField.GET_PARTITIONS_USED, TelemetryData.TRUE
10281026
)

src/snowflake/connector/aio/_file_transfer_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ async def execute(self) -> None:
118118
# multichunk threshold
119119
m.multipart_threshold = self._multipart_threshold
120120

121-
# TODO: https://snowflakecomputing.atlassian.net/browse/SNOW-1625364
121+
# TODO: SNOW-1625364 for renaming client_prefetch_threads in asyncio
122122
logger.debug(f"parallel=[{self._parallel}]")
123123
if self._raise_put_get_error and not self._file_metadata:
124124
Error.errorhandler_wrapper(
@@ -238,7 +238,7 @@ def postprocess_done_cb(
238238
task_of_files = []
239239
for file_client in files:
240240
try:
241-
# TODO: https://snowflakecomputing.atlassian.net/browse/SNOW-1708819
241+
# TODO: SNOW-1708819 for code refactoring
242242
res = (
243243
await file_client.prepare_upload()
244244
if is_upload

src/snowflake/connector/aio/_network.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,9 @@ async def _post_request(
467467
_include_retry_params: bool = False,
468468
) -> dict[str, Any]:
469469
full_url = f"{self.server_url}{url}"
470-
# TODO: sync feature parity, probe connection
471-
# if self._connection._probe_connection:
472-
# from pprint import pprint
473-
#
474-
# ret = probe_connection(full_url)
475-
# pprint(ret)
470+
if self._connection._probe_connection:
471+
# TODO: SNOW-1572318 for probe connection
472+
raise NotImplementedError("probe_connection is not supported in asyncio")
476473

477474
ret = await self.fetch(
478475
"post",
@@ -716,8 +713,6 @@ async def _request_exec(
716713
else:
717714
input_data = data
718715

719-
# TODO: aiohttp auth parameter works differently than requests.session.request
720-
# we can check if there's other aiohttp built-in mechanism to update this
721716
if HEADER_AUTHORIZATION_KEY in headers:
722717
del headers[HEADER_AUTHORIZATION_KEY]
723718
if token != NO_TOKEN:
@@ -745,7 +740,7 @@ async def _request_exec(
745740
if is_raw_text:
746741
ret = await raw_ret.text()
747742
elif is_raw_binary:
748-
# check SNOW-1738595 for is_raw_binary support
743+
# TODO: SNOW-1738595 for is_raw_binary support
749744
raise NotImplementedError(
750745
"reading raw binary data is not supported in asyncio connector,"
751746
" please open a feature request issue in"

src/snowflake/connector/aio/auth/_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async def authenticate(
6969
timeout: int | None = None,
7070
) -> dict[str, str | int | bool]:
7171
if mfa_callback or password_callback:
72-
# check SNOW-1707210 for mfa_callback and password_callback support
72+
# TODO: SNOW-1707210 for mfa_callback and password_callback support
7373
raise NotImplementedError(
7474
"mfa_callback or password_callback is not supported in asyncio connector, please open a feature"
7575
" request issue in github: https://github.com/snowflakedb/snowflake-connector-python/issues/new/choose"

test/integ/aio/test_connection_async.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,8 +1517,8 @@ async def test_mock_non_existing_server(conn_cnx, caplog):
15171517
)
15181518

15191519

1520-
@pytest.mark.skip(
1521-
"SNOW-1759084 await anext(self._generator, None) does not execute code after yield"
1520+
@pytest.mark.xfail(
1521+
reason="TODO: SNOW-1759084 await anext(self._generator, None) does not execute code after yield"
15221522
)
15231523
async def test_disable_telemetry(conn_cnx, caplog):
15241524
# default behavior, closing connection, it will send telemetry
@@ -1528,7 +1528,8 @@ async def test_disable_telemetry(conn_cnx, caplog):
15281528
await (await cur.execute("select 1")).fetchall()
15291529
assert (
15301530
len(conn._telemetry._log_batch) == 3
1531-
) # 3 events are import package, fetch first, fetch last
1531+
) # 3 events are `import package`, `fetch first`, it's missing `fetch last` because of SNOW-1759084
1532+
15321533
assert "POST /telemetry/send" in caplog.text
15331534
caplog.clear()
15341535

test/integ/aio/test_cursor_async.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -984,14 +984,14 @@ async def test_real_decimal(conn, db_parameters):
984984
assert rec["RATIO"] == decimal.Decimal("23.4"), "the decimal value"
985985

986986

987-
@pytest.mark.skip("SNOW-1763103")
987+
@pytest.mark.skip("SNOW-1763103 error handler async")
988988
async def test_none_errorhandler(conn_testaccount):
989989
c = conn_testaccount.cursor()
990990
with pytest.raises(errors.ProgrammingError):
991991
c.errorhandler = None
992992

993993

994-
@pytest.mark.skip("SNOW-1763103")
994+
@pytest.mark.skip("SNOW-1763103 error handler async")
995995
async def test_nope_errorhandler(conn_testaccount):
996996
def user_errorhandler(connection, cursor, errorclass, errorvalue):
997997
pass
@@ -1432,9 +1432,6 @@ async def test__log_telemetry_job_data(conn_cnx, caplog):
14321432
) in caplog.record_tuples
14331433

14341434

1435-
@pytest.mark.skip(
1436-
reason="SNOW-1759076 Async for support in Cursor.get_result_batches()"
1437-
)
14381435
@pytest.mark.parametrize(
14391436
"result_format,expected_chunk_type",
14401437
(
@@ -1446,7 +1443,7 @@ async def test_resultbatch(
14461443
conn_cnx,
14471444
result_format,
14481445
expected_chunk_type,
1449-
capture_sf_telemetry,
1446+
capture_sf_telemetry_async,
14501447
):
14511448
"""This test checks the following things:
14521449
1. After executing a query can we pickle the result batches
@@ -1461,13 +1458,13 @@ async def test_resultbatch(
14611458
"python_connector_query_result_format": result_format,
14621459
}
14631460
) as con:
1464-
with capture_sf_telemetry.patch_connection(con) as telemetry_data:
1465-
with con.cursor() as cur:
1466-
cur.execute(
1461+
async with capture_sf_telemetry_async.patch_connection(con) as telemetry_data:
1462+
async with con.cursor() as cur:
1463+
await cur.execute(
14671464
f"select seq4() from table(generator(rowcount => {rowcount}));"
14681465
)
14691466
assert cur._result_set.total_row_index() == rowcount
1470-
pre_pickle_partitions = cur.get_result_batches()
1467+
pre_pickle_partitions = await cur.get_result_batches()
14711468
assert len(pre_pickle_partitions) > 1
14721469
assert pre_pickle_partitions is not None
14731470
assert all(
@@ -1481,7 +1478,7 @@ async def test_resultbatch(
14811478
post_pickle_partitions: list[ResultBatch] = pickle.loads(pickle_str)
14821479
total_rows = 0
14831480
# Make sure the batches can be iterated over individually
1484-
async for it in post_pickle_partitions:
1481+
for it in post_pickle_partitions:
14851482
print(it)
14861483

14871484
for i, partition in enumerate(post_pickle_partitions):
@@ -1492,15 +1489,17 @@ async def test_resultbatch(
14921489
else:
14931490
assert partition.compressed_size is not None
14941491
assert partition.uncompressed_size is not None
1495-
for row in partition:
1492+
# TODO: SNOW-1759076 Async for support in Cursor.get_result_batches()
1493+
for row in await partition.create_iter():
14961494
col1 = row[0]
14971495
assert col1 == total_rows
14981496
total_rows += 1
14991497
assert total_rows == rowcount
15001498
total_rows = 0
15011499
# Make sure the batches can be iterated over again
15021500
for partition in post_pickle_partitions:
1503-
for row in partition:
1501+
# TODO: SNOW-1759076 Async for support in Cursor.get_result_batches()
1502+
for row in await partition.create_iter():
15041503
col1 = row[0]
15051504
assert col1 == total_rows
15061505
total_rows += 1

test/integ/aio/test_dbapi_async.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ async def test_exceptions():
115115
assert issubclass(errors.NotSupportedError, errors.Error)
116116

117117

118+
@pytest.mark.skip("SNOW-1770153 for error as attribute on connection")
118119
async def test_exceptions_as_connection_attributes(conn_cnx):
119120
async with conn_cnx() as con:
120121
try:

test/integ/aio/test_errors_async.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from snowflake.connector.telemetry import TelemetryField
1515

1616

17+
@pytest.mark.skip("SNOW-1770153 for error as attribute on connection")
1718
async def test_error_classes(conn_cnx):
1819
"""Error classes in Connector module, object."""
1920
# class

0 commit comments

Comments
 (0)