fix(sql_database): map FLOAT/REAL/DOUBLE to double under SQLAlchemy 2.1 - #4341
Open
Aryan-Pardeshi wants to merge 1 commit into
Open
fix(sql_database): map FLOAT/REAL/DOUBLE to double under SQLAlchemy 2.1#4341Aryan-Pardeshi wants to merge 1 commit into
Aryan-Pardeshi wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4313
Problem
sqla_col_to_column_schemadispatches float columns viaisinstance(sql_t, sqltypes.Numeric). In SQLAlchemy 2.1,Float(andREAL/DOUBLE) no longer subclassNumeric— both now derive from the newNumericCommonbase — so FLOAT/REAL/DOUBLE columns fall through to the unknown-type warning branch and lose theirdata_typeentirely.Change
Add a dedicated
isinstance(sql_t, sqltypes.Float)branch after theNumericbranch, mapping float types todata_type: "double"(the same value the Numeric branch produces forasdecimal=False). Version-safe: on SA < 2.1 the Numeric branch still matches first; on 2.1 the Float branch catchesFloat/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 (whereissubclass(Float, Numeric) is False).