From e51c4d0a63725cc89e65520bb3425c80b6f3baff Mon Sep 17 00:00:00 2001 From: Jesse Dobbelaere Date: Mon, 21 Nov 2022 20:39:45 +0100 Subject: [PATCH 1/2] Fix thread issues by removing global boto3 session --- dbt/adapters/athena/session.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/dbt/adapters/athena/session.py b/dbt/adapters/athena/session.py index 0b186e45..b6185974 100644 --- a/dbt/adapters/athena/session.py +++ b/dbt/adapters/athena/session.py @@ -1,24 +1,12 @@ -from typing import Optional - import boto3.session from dbt.contracts.connection import Connection -__BOTO3_SESSION__: Optional[boto3.session.Session] = None - def get_boto3_session(connection: Connection = None) -> boto3.session.Session: - def init_session(): - global __BOTO3_SESSION__ - __BOTO3_SESSION__ = boto3.session.Session( - region_name=connection.credentials.region_name, - profile_name=connection.credentials.aws_profile_name, - ) - - if not __BOTO3_SESSION__: - if connection is None: - raise RuntimeError( - "A Connection object needs to be passed to initialize the boto3 session for the first time" - ) - init_session() + if connection is None: + raise RuntimeError("A Connection object needs to be passed to initialize the boto3 session") - return __BOTO3_SESSION__ + return boto3.session.Session( + region_name=connection.credentials.region_name, + profile_name=connection.credentials.aws_profile_name, + ) From 827dab9e6afb031f92a033caedef81ba937ad0fe Mon Sep 17 00:00:00 2001 From: Jesse Dobbelaere Date: Tue, 22 Nov 2022 11:29:25 +0100 Subject: [PATCH 2/2] Cleanup connection None --- dbt/adapters/athena/session.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/dbt/adapters/athena/session.py b/dbt/adapters/athena/session.py index b6185974..c28ab00a 100644 --- a/dbt/adapters/athena/session.py +++ b/dbt/adapters/athena/session.py @@ -2,10 +2,7 @@ from dbt.contracts.connection import Connection -def get_boto3_session(connection: Connection = None) -> boto3.session.Session: - if connection is None: - raise RuntimeError("A Connection object needs to be passed to initialize the boto3 session") - +def get_boto3_session(connection: Connection) -> boto3.session.Session: return boto3.session.Session( region_name=connection.credentials.region_name, profile_name=connection.credentials.aws_profile_name,