Skip to content

Commit 909f61c

Browse files
authored
Merge pull request #582 from dbt-msft/581-importerror-cannot-import-name-get_pyodbc_attrs_before-from-dbtadaptersfabricfabric_connection_manager
Fix broken imports from Fabric
2 parents 0330613 + 42bebf5 commit 909f61c

File tree

4 files changed

+12
-53
lines changed

4 files changed

+12
-53
lines changed

dbt/adapters/sqlserver/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "1.8.4"
1+
version = "1.8.5"

dbt/adapters/sqlserver/sqlserver_connections.py

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from dbt.adapters.fabric.fabric_connection_manager import (
1212
AZURE_CREDENTIAL_SCOPE,
1313
bool_to_connection_string_arg,
14-
get_pyodbc_attrs_before,
14+
get_pyodbc_attrs_before_accesstoken,
15+
get_pyodbc_attrs_before_credentials,
1516
)
1617

1718
from dbt.adapters.sqlserver import __version__
@@ -70,27 +71,6 @@ def get_sp_access_token(credentials: SQLServerCredentials) -> AccessToken:
7071
class SQLServerConnectionManager(FabricConnectionManager):
7172
TYPE = "sqlserver"
7273

73-
# @contextmanager
74-
# def exception_handler(self, sql: str):
75-
# """
76-
# Returns a context manager, that will handle exceptions raised
77-
# from queries, catch, log, and raise dbt exceptions it knows how to handle.
78-
# """
79-
# # ## Example ##
80-
# # try:
81-
# # yield
82-
# # except myadapter_library.DatabaseError as exc:
83-
# # self.release(connection_name)
84-
85-
# # logger.debug("myadapter error: {}".format(str(e)))
86-
# # raise dbt.exceptions.DatabaseException(str(exc))
87-
# # except Exception as exc:
88-
# # logger.debug("Error running SQL: {}".format(sql))
89-
# # logger.debug("Rolling back transaction.")
90-
# # self.release(connection_name)
91-
# # raise dbt.exceptions.RuntimeException(str(exc))
92-
# pass
93-
9474
@classmethod
9575
def open(cls, connection: Connection) -> Connection:
9676
if connection.state == ConnectionState.OPEN:
@@ -156,7 +136,11 @@ def open(cls, connection: Connection) -> Connection:
156136
def connect():
157137
logger.debug(f"Using connection string: {con_str_display}")
158138

159-
attrs_before = get_pyodbc_attrs_before(credentials)
139+
if credentials.authentication == "ActiveDirectoryAccessToken":
140+
attrs_before = get_pyodbc_attrs_before_accesstoken(credentials.access_token)
141+
else:
142+
attrs_before = get_pyodbc_attrs_before_credentials(credentials)
143+
160144
handle = pyodbc.connect(
161145
con_str_concat,
162146
attrs_before=attrs_before,
@@ -174,28 +158,3 @@ def connect():
174158
retry_limit=credentials.retries,
175159
retryable_exceptions=retryable_exceptions,
176160
)
177-
178-
# @classmethod
179-
# def get_response(cls,cursor):
180-
# """
181-
# Gets a cursor object and returns adapter-specific information
182-
# about the last executed command generally a AdapterResponse ojbect
183-
# that has items such as code, rows_affected,etc. can also just be a string ex. "OK"
184-
# if your cursor does not offer rich metadata.
185-
# """
186-
# # ## Example ##
187-
# # return cursor.status_message
188-
# pass
189-
190-
# def cancel(self, connection):
191-
# """
192-
# Gets a connection object and attempts to cancel any ongoing queries.
193-
# """
194-
# # ## Example ##
195-
# # tid = connection.handle.transaction_id()
196-
# # sql = "select cancel_transaction({})".format(tid)
197-
# # logger.debug("Cancelling query "{}" ({})".format(connection_name, pid))
198-
# # _, cursor = self.add_query(sql, "master")
199-
# # res = cursor.fetchone()
200-
# # logger.debug("Canceled query "{}": {}".format(connection_name, res))
201-
# pass

tests/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from dbt.adapters.sqlserver.sqlserver_connections import ( # byte_array_to_datetime,
55
bool_to_connection_string_arg,
6-
get_pyodbc_attrs_before,
6+
get_pyodbc_attrs_before_credentials,
77
)
88
from dbt.adapters.sqlserver.sqlserver_credentials import SQLServerCredentials
99

@@ -29,7 +29,7 @@ def test_get_pyodbc_attrs_before_empty_dict_when_service_principal(
2929
"""
3030
When the authentication is set to sql we expect an empty attrs before.
3131
"""
32-
attrs_before = get_pyodbc_attrs_before(credentials)
32+
attrs_before = get_pyodbc_attrs_before_credentials(credentials)
3333
assert attrs_before == {}
3434

3535

tests/unit/adapters/mssql/test_sqlserver_connection_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from dbt.adapters.sqlserver.sqlserver_connections import ( # byte_array_to_datetime,
55
bool_to_connection_string_arg,
6-
get_pyodbc_attrs_before,
6+
get_pyodbc_attrs_before_credentials,
77
)
88
from dbt.adapters.sqlserver.sqlserver_credentials import SQLServerCredentials
99

@@ -29,7 +29,7 @@ def test_get_pyodbc_attrs_before_empty_dict_when_service_principal(
2929
"""
3030
When the authentication is set to sql we expect an empty attrs before.
3131
"""
32-
attrs_before = get_pyodbc_attrs_before(credentials)
32+
attrs_before = get_pyodbc_attrs_before_credentials(credentials)
3333
assert attrs_before == {}
3434

3535

0 commit comments

Comments
 (0)