Skip to content

Fix the ARRAY, MAP and ROW regressions against 4.4.0 from #1577 and #1630 #1657

Backlog

Description

@laughingman7743

Problem

The independent review of the 4.x backport #1652 (Codex, static) reported, and an offline check confirmed, statements and results that work on 4.4.0 (4.x da0590d) and fail or change after #1577 (GH-1569) and #1630 (GH-1616, commit 32fd6bb). The code is the same on master, so 5.0.0 would ship these as regressions against 4.4.0, and the 4.4.1 backport #1652 would carry them too.

  1. An ARRAY of an unhashable Float TypeDecorator fails to decode (Decode float ARRAY elements and import the compliance suite on SQLAlchemy 2.1 (GH-1569) #1577). AthenaArray(D()).result_processor(dialect, None)('["1.5"]') with class D(TypeDecorator): impl = Float; __hash__ = None returns [1.5] on 4.4.0 (SQLAlchemy 2.0.44) and raises TypeError: unhashable type: 'D' after Decode float ARRAY elements and import the compliance suite on SQLAlchemy 2.1 (GH-1569) #1577. The processor cache is keyed by id(), but resolving the implementation calls dialect_impl(), which hashes the decorator.
  2. NULL for a MAP or ROW with a precision-less Numeric raises (Render timedelta, MAP, and ROW values as Athena literals (GH-1616) #1630). insert(t).values(m=None) for Column("m", AthenaMap(String, Numeric())) renders INSERT INTO t (m) VALUES (null) on 4.4.0 and raises CompileError: ARRAY, MAP, and ROW decimal values require explicit Numeric precision after Render timedelta, MAP, and ROW values as Athena literals (GH-1616) #1630, also when compiled without executing. A NULL value has no decimal to round.
  3. ROW and MAP casts that differ only by a variant share a compiled-cache key (Render timedelta, MAP, and ROW values as Athena literals (GH-1616) #1630). literal((1,), AthenaStruct(("x", String()))) and literal((1,), AthenaStruct(("x", String().with_variant(Integer(), "awsathena")))) have equal cache keys (the field key uses _static_cache_key, which omits the variant: pyathena/sqlalchemy/struct.py), but now render different SQL: CAST(ROW(1) AS ROW(x VARCHAR)) and CAST(ROW(1) AS ROW(x INTEGER)). With one engine, the second statement can reuse the first's compiled SQL and bind processors. On 4.4.0 the keys were equal as well, but both rendered (1). Check MAP key and value types the same way.
  4. A ROW comparison now rounds a bound Decimal before comparing (Render timedelta, MAP, and ROW values as Athena literals (GH-1616) #1630; behavior change). r == (Decimal("1.234"), "x") for r of ROW(n DECIMAL(5, 2), tag VARCHAR) renders r = (DECIMAL '1.234', 'x') on 4.4.0 and r = CAST(ROW(DECIMAL '1.234', 'x') AS ROW(n DECIMAL(5, 2), tag VARCHAR)) after Render timedelta, MAP, and ROW values as Athena literals (GH-1616) #1630, so a stored (1.23, 'x') now matches. Decide whether this follows the declared type as intended (as == casts other values) or should keep the value's precision.

Reproduction

Offline, on 4.x da0590d and on the backport head dcee17f (= master's code), SQLAlchemy 2.0.44 and 2.1.9, with the dialect AthenaDialect(). The outputs are in the review record on #1652.

Environment

master after #1577 (4c971ae) and #1630 (bb0a896); 4.x with #1652. SQLAlchemy 2.0.44 to 2.1.9.

Proposed fix (optional)

Fix 1 to 3 on master (resolve the implementation of an unhashable decorator without hashing it; skip the precision check for NULL; include the full declared types, variants included, in the cache key of MAP and ROW). Decide 4. Then add the fixes to the 4.x backport #1652 before it is marked Ready.

Activity

  1. added this to the 5.0.0 milestone on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions