Skip to content

Commit 957c85c

Browse files
committed
SNOW-1740361: raise error below python less than 3 10 (#2075)
1 parent c5b4e47 commit 957c85c

File tree

6 files changed

+98
-13
lines changed

6 files changed

+98
-13
lines changed

.github/workflows/build_test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,36 @@ jobs:
395395
.tox/.coverage
396396
.tox/coverage.xml
397397
398+
test-unsupporeted-aio:
399+
name: Test unsupported asyncio ${{ matrix.os.download_name }}-${{ matrix.python-version }}
400+
runs-on: ${{ matrix.os.image_name }}
401+
strategy:
402+
fail-fast: false
403+
matrix:
404+
os:
405+
- image_name: ubuntu-latest
406+
download_name: manylinux_x86_64
407+
python-version: [ "3.8", "3.9" ]
408+
steps:
409+
- uses: actions/checkout@v4
410+
- name: Set up Python
411+
uses: actions/setup-python@v4
412+
with:
413+
python-version: ${{ matrix.python-version }}
414+
- name: Display Python version
415+
run: python -c "import sys; print(sys.version)"
416+
- name: Upgrade setuptools, pip and wheel
417+
run: python -m pip install -U setuptools pip wheel
418+
- name: Install tox
419+
run: python -m pip install tox>=4
420+
- name: Run tests
421+
run: python -m tox run -e aio-unsupported-python
422+
env:
423+
PYTHON_VERSION: ${{ matrix.python-version }}
424+
PYTEST_ADDOPTS: --color=yes --tb=short
425+
TOX_PARALLEL_NO_SPINNER: 1
426+
shell: bash
427+
398428
combine-coverage:
399429
if: ${{ success() || failure() }}
400430
name: Combine coverage

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ development =
9292
pytest-xdist
9393
pytzdata
9494
pytest-asyncio
95-
aiohttp
9695
pandas =
9796
pandas>=1.0.0,<3.0.0
9897
pyarrow

src/snowflake/connector/aio/_result_set.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Deque,
1919
Iterator,
2020
Literal,
21+
Union,
2122
cast,
2223
overload,
2324
)
@@ -156,7 +157,7 @@ def __init__(
156157
) -> None:
157158
super().__init__(cursor, result_chunks, prefetch_thread_num)
158159
self.batches = cast(
159-
list[JSONResultBatch] | list[ArrowResultBatch], self.batches
160+
Union[list[JSONResultBatch], list[ArrowResultBatch]], self.batches
160161
)
161162

162163
def _can_create_arrow_iter(self) -> None:

src/snowflake/connector/aio/_ssl_connector.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import annotations
66

77
import logging
8+
import sys
89
from typing import TYPE_CHECKING
910

1011
import aiohttp
@@ -27,15 +28,19 @@
2728

2829
class SnowflakeSSLConnector(aiohttp.TCPConnector):
2930
def __init__(self, *args, **kwargs):
30-
import sys
31-
32-
if sys.version_info <= (3, 9):
33-
raise RuntimeError(
34-
"The asyncio support for Snowflake Python Connector is only supported on Python 3.10 or greater."
35-
)
3631
self._snowflake_ocsp_mode = kwargs.pop(
3732
"snowflake_ocsp_mode", OCSPMode.FAIL_OPEN
3833
)
34+
if self._snowflake_ocsp_mode == OCSPMode.FAIL_OPEN and sys.version_info < (
35+
3,
36+
10,
37+
):
38+
raise RuntimeError(
39+
"Async Snowflake Python Connector requires Python 3.10+ for OCSP validation related features. "
40+
"Please open a feature request issue in github if your want to use Python 3.9 or lower: "
41+
"https://github.com/snowflakedb/snowflake-connector-python/issues/new/choose."
42+
)
43+
3944
super().__init__(*args, **kwargs)
4045

4146
async def connect(
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#
2+
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
3+
#
4+
5+
import asyncio
6+
import sys
7+
8+
import snowflake.connector.aio
9+
10+
assert (
11+
sys.version_info.major == 3 and sys.version_info.minor <= 9
12+
), "This test is only for Python 3.9 and lower"
13+
14+
15+
CONNECTION_PARAMETERS = {
16+
"account": "test",
17+
"user": "test",
18+
"password": "test",
19+
"schema": "test",
20+
"database": "test",
21+
"protocol": "test",
22+
"host": "test.snowflakecomputing.com",
23+
"warehouse": "test",
24+
"port": 443,
25+
"role": "test",
26+
}
27+
28+
29+
async def main():
30+
try:
31+
async with snowflake.connector.aio.SnowflakeConnection(**CONNECTION_PARAMETERS):
32+
pass
33+
except Exception as exc:
34+
assert isinstance(
35+
exc, RuntimeError
36+
) and "Async Snowflake Python Connector requires Python 3.10+" in str(
37+
exc
38+
), "should raise RuntimeError"
39+
40+
41+
asyncio.run(main())

tox.ini

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ setenv =
4343
SNOWFLAKE_PYTEST_COV_LOCATION = {env:JUNIT_REPORT_DIR:{toxworkdir}}/junit.{envname}-{env:cloud_provider:dev}.xml
4444
SNOWFLAKE_PYTEST_COV_CMD = --cov snowflake.connector --junitxml {env:SNOWFLAKE_PYTEST_COV_LOCATION} --cov-report=
4545
SNOWFLAKE_PYTEST_CMD = pytest {env:SNOWFLAKE_PYTEST_OPTS:} {env:SNOWFLAKE_PYTEST_COV_CMD}
46+
SNOWFLAKE_PYTEST_CMD_IGNORE_AIO = {env:SNOWFLAKE_PYTEST_CMD} --ignore=test/integ/aio --ignore=test/unit/aio
4647
SNOWFLAKE_TEST_MODE = true
4748
passenv =
4849
AWS_ACCESS_KEY_ID
@@ -61,10 +62,10 @@ passenv =
6162
commands =
6263
# Test environments
6364
# Note: make sure to have a default env and all the other special ones
64-
!pandas-!sso-!lambda-!extras: {env:SNOWFLAKE_PYTEST_CMD} -m "{env:SNOWFLAKE_TEST_TYPE} and not sso and not pandas and not lambda and not aio" {posargs:} test
65-
pandas: {env:SNOWFLAKE_PYTEST_CMD} -m "{env:SNOWFLAKE_TEST_TYPE} and pandas and not aio" {posargs:} test
66-
sso: {env:SNOWFLAKE_PYTEST_CMD} -m "{env:SNOWFLAKE_TEST_TYPE} and sso and not aio" {posargs:} test
67-
lambda: {env:SNOWFLAKE_PYTEST_CMD} -m "{env:SNOWFLAKE_TEST_TYPE} and lambda and not aio" {posargs:} test
65+
!pandas-!sso-!lambda-!extras: {env:SNOWFLAKE_PYTEST_CMD_IGNORE_AIO} -m "{env:SNOWFLAKE_TEST_TYPE} and not sso and not pandas and not lambda and not aio" {posargs:} test
66+
pandas: {env:SNOWFLAKE_PYTEST_CMD_IGNORE_AIO} -m "{env:SNOWFLAKE_TEST_TYPE} and pandas and not aio" {posargs:} test
67+
sso: {env:SNOWFLAKE_PYTEST_CMD_IGNORE_AIO} -m "{env:SNOWFLAKE_TEST_TYPE} and sso and not aio" {posargs:} test
68+
lambda: {env:SNOWFLAKE_PYTEST_CMD_IGNORE_AIO} -m "{env:SNOWFLAKE_TEST_TYPE} and lambda and not aio" {posargs:} test
6869
extras: python -m test.extras.run {posargs:}
6970

7071
[testenv:olddriver]
@@ -87,7 +88,7 @@ skip_install = True
8788
setenv = {[testenv]setenv}
8889
passenv = {[testenv]passenv}
8990
commands =
90-
{env:SNOWFLAKE_PYTEST_CMD} -m "not skipolddriver" -vvv {posargs:} test --ignore=test/integ/aio --ignore=test/unit/aio
91+
{env:SNOWFLAKE_PYTEST_CMD_IGNORE_AIO} -m "not skipolddriver" -vvv {posargs:} test
9192

9293
[testenv:noarrowextension]
9394
basepython = python3.8
@@ -106,6 +107,14 @@ extras=
106107
pandas
107108
commands = {env:SNOWFLAKE_PYTEST_CMD} -m "aio" -vvv {posargs:} test
108109

110+
[testenv:aio-unsupported-python]
111+
description = Run aio connector on unsupported python versions
112+
extras=
113+
aio
114+
commands =
115+
pip install .
116+
python test/aiodep/unsupported_python_version.py
117+
109118
[testenv:coverage]
110119
description = [run locally after tests]: combine coverage data and create report
111120
; generates a diff coverage against origin/master (can be changed by setting DIFF_AGAINST env var)

0 commit comments

Comments
 (0)