Skip to content

fix(sql_database): map FLOAT/REAL/DOUBLE to double under SQLAlchemy 2.1 - #4341

Open
Aryan-Pardeshi wants to merge 1 commit into
dlt-hub:develfrom
Aryan-Pardeshi:fix/4313-float-numericcommon
Open

fix(sql_database): map FLOAT/REAL/DOUBLE to double under SQLAlchemy 2.1#4341
Aryan-Pardeshi wants to merge 1 commit into
dlt-hub:develfrom
Aryan-Pardeshi:fix/4313-float-numericcommon

Conversation

@Aryan-Pardeshi

Copy link
Copy Markdown

Fixes #4313

Problem

sqla_col_to_column_schema dispatches float columns via isinstance(sql_t, sqltypes.Numeric). In SQLAlchemy 2.1, Float (and REAL/DOUBLE) no longer subclass Numeric — both now derive from the new NumericCommon base — so FLOAT/REAL/DOUBLE columns fall through to the unknown-type warning branch and lose their data_type entirely.

Change

Add a dedicated isinstance(sql_t, sqltypes.Float) branch after the Numeric branch, mapping float types to data_type: "double" (the same value the Numeric branch produces for asdecimal=False). Version-safe: on SA < 2.1 the Numeric branch still matches first; on 2.1 the Float branch catches Float/REAL/Double.

Tests

  • test_float_types_mapped_to_double (sa.Float, sa.REAL)
  • test_double_mapped_to_double_sa2 (sa.Double, SA >= 2.0)
  • test_numeric_mapped_to_decimal_not_shadowed (Numeric(10,2) still → decimal + precision/scale)

Verified: tests/sources/sql_database/test_schema_types.py — 21 passed under SQLAlchemy 2.0.51 and 2.1.0b3 (where issubclass(Float, Numeric) is False).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql_database: FLOAT/REAL/DOUBLE columns lose data_type under SQLAlchemy 2.1 (Float no longer subclasses Numeric)

1 participant