Skip to content

Commit f2328b8

Browse files
refactor: Drop redundant output converter.
DATETIMEOFFSET is natively supported by `mssql-python`. See "microsoft/mssql-python#213"
1 parent 435af83 commit f2328b8

File tree

1 file changed

+0
-23
lines changed

1 file changed

+0
-23
lines changed

sqlmesh/core/config/connection.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,29 +1693,6 @@ def connect_mssql_python(**kwargs: t.Any) -> t.Callable:
16931693

16941694
conn = mssql_python.connect(conn_str, autocommit=kwargs.get("autocommit", False))
16951695

1696-
# Set up output converters for MSSQL-specific data types
1697-
# Handle SQL type -155 (DATETIMEOFFSET) which is not yet supported by pyodbc
1698-
# ref: https://github.com/mkleehammer/pyodbc/issues/134#issuecomment-281739794
1699-
def handle_datetimeoffset_mssql_python(dto_value: t.Any) -> t.Any:
1700-
import struct
1701-
from datetime import datetime, timedelta, timezone
1702-
1703-
# Unpack the DATETIMEOFFSET binary format:
1704-
# Format: <6hI2h = (year, month, day, hour, minute, second, nanoseconds, tz_hour_offset, tz_minute_offset)
1705-
tup = struct.unpack("<6hI2h", dto_value)
1706-
return datetime(
1707-
tup[0],
1708-
tup[1],
1709-
tup[2],
1710-
tup[3],
1711-
tup[4],
1712-
tup[5],
1713-
tup[6] // 1000,
1714-
timezone(timedelta(hours=tup[7], minutes=tup[8])),
1715-
)
1716-
1717-
conn.add_output_converter(-155, handle_datetimeoffset_mssql_python)
1718-
17191696
return conn
17201697

17211698
return connect_mssql_python

0 commit comments

Comments
 (0)