Skip to content

Commit

Permalink
make sql database pipeline tests succeed on both sqlalchemy versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed Sep 4, 2024
1 parent e449ad2 commit a365f62
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions dlt/sources/sql_database/schema_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def default_table_adapter(table: Table, included_columns: Optional[List[str]]) -
table._columns.remove(col) # type: ignore[attr-defined]
for col in table._columns: # type: ignore[attr-defined]
sql_t = col.type
if isinstance(sql_t, sqltypes.Uuid): # type: ignore[attr-defined]
if hasattr(sqltypes, "Uuid") and isinstance(sql_t, sqltypes.Uuid):
# emit uuids as string by default
sql_t.as_uuid = False

Expand Down Expand Up @@ -79,7 +79,7 @@ def sqla_col_to_column_schema(

add_precision = reflection_level == "full_with_precision"

if isinstance(sql_t, sqltypes.Uuid): # type: ignore[attr-defined]
if hasattr(sqltypes, "Uuid") and isinstance(sql_t, sqltypes.Uuid):
# we represent UUID as text by default, see default_table_adapter
col["data_type"] = "text"
if isinstance(sql_t, sqltypes.Numeric):
Expand Down
4 changes: 2 additions & 2 deletions dlt/sources/sql_database_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ def my_sql_via_pyarrow() -> None:
)

def _double_as_decimal_adapter(table: sa.Table) -> None:
"""Return double as double, not decimals"""
"""Return double as double, not decimals, only works if you are using sqlalchemy 2.0"""
for column in table.columns.values():
if isinstance(column.type, sa.Double): # type: ignore
if hasattr(sa, "Double") and isinstance(column.type, sa.Double):
column.type.asdecimal = False

sql_alchemy_source = sql_database(
Expand Down

0 comments on commit a365f62

Please sign in to comment.