From fef5c34f69888f8d15000a4733d669777676bc5d Mon Sep 17 00:00:00 2001 From: "tim.reichard" Date: Tue, 1 Jun 2021 13:36:54 -0500 Subject: [PATCH] Add attr_before parameter in pyodbc.connect --- HISTORY.rst | 6 ++++++ aioradio/file_ingestion.py | 11 +++++------ aioradio/pyodbc.py | 3 ++- aioradio/requirements.txt | 22 +++++++++++----------- setup.py | 2 +- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index ebc28b0..1bd3063 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,12 @@ History ======= +v0.13.7 (2021-06-02) +----------------------- + +* Add attr_before parameter in pyodbc.connect. + + v0.13.5 (2021-04-27) ----------------------- diff --git a/aioradio/file_ingestion.py b/aioradio/file_ingestion.py index 9ec3964..2c426e0 100644 --- a/aioradio/file_ingestion.py +++ b/aioradio/file_ingestion.py @@ -164,13 +164,12 @@ async def unzip_file(filepath: str, directory: str) -> List[str]: List[str]: List of filenames """ - zipped = zipfile.ZipFile(filepath) + filenames = [] + with zipfile.ZipFile(filepath) as zipped: - # exclude __MACOSX directory that could be added when creating zip on macs - filenames = [i for i in zipped.namelist() if '__MACOSX' not in i] - - zipped.extractall(directory) - zipped.close() + # exclude __MACOSX directory that could be added when creating zip on macs + filenames = [i for i in zipped.namelist() if '__MACOSX' not in i] + zipped.extractall(directory) return filenames diff --git a/aioradio/pyodbc.py b/aioradio/pyodbc.py index 3bbd97c..837d26c 100644 --- a/aioradio/pyodbc.py +++ b/aioradio/pyodbc.py @@ -11,6 +11,7 @@ import pyodbc OPERATING_SYSTEM = platform.system() +SQL_ATTR_CONNECTION_TIMEOUT = 113 # driver location varies based on OS. add to this list if necessary... UNIXODBC_DRIVER_PATHS = [ @@ -92,7 +93,7 @@ async def establish_pyodbc_connection( if multi_subnet_failover: conn_string += f';MultiSubnetFailover={multi_subnet_failover}' - return pyodbc.connect(conn_string, autocommit=autocommit) + return pyodbc.connect(conn_string, autocommit=autocommit, attr_before={SQL_ATTR_CONNECTION_TIMEOUT: 3}) async def pyodbc_query_fetchone(conn: pyodbc.Connection, query: str) -> Union[List[Any], None]: diff --git a/aioradio/requirements.txt b/aioradio/requirements.txt index 7e55718..45f6001 100644 --- a/aioradio/requirements.txt +++ b/aioradio/requirements.txt @@ -1,21 +1,21 @@ aioboto3==8.3.0 aiobotocore==1.3.0 aiojobs==0.3.0 -ddtrace==0.48.0 -fakeredis==1.5.0 -flask==1.1.2 -httpx==0.17.1 +ddtrace==0.49.2 +fakeredis==1.5.1 +flask==2.0.1 +httpx==0.18.1 mandrill==1.0.60 moto==1.3.16 -orjson==3.5.1 -pre-commit==2.12.0 +orjson==3.5.3 +pre-commit==2.13.0 psycopg2-binary==2.8.6 -pylint==2.7.4 +pylint==2.8.3 pyodbc==4.0.30 -pysmb==1.2.6 -pytest==6.2.3 -pytest-asyncio==0.14.0 -pytest-cov==2.11.1 +pysmb==1.2.7 +pytest==6.2.4 +pytest-asyncio==0.15.1 +pytest-cov==2.12.1 python-json-logger==2.0.1 redis==3.5.3 twine==3.4.1 diff --git a/setup.py b/setup.py index 656253c..164b99a 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ long_description = fileobj.read() setup(name='aioradio', - version='0.13.6', + version='0.13.7', description='Generic asynchronous i/o python utilities for AWS services (SQS, S3, DynamoDB, Secrets Manager), Redis, MSSQL (pyodbc), JIRA and more', long_description=long_description, long_description_content_type="text/markdown",