Change8

rel_2_0_44

📦 sqlalchemyView on GitHub →
2 features🐛 11 fixes2 deprecations🔧 9 symbols

Summary

SQLAlchemy 2.0.44 introduces refined ORM type‑alias handling, adds the `_orm.mapped_as_dataclass()` decorator, and fixes numerous bugs across platforms, engines, and dialects.

Migration Steps

  1. If your code relies on recursive PEP 695 type alias resolution or implicit `NewType` lookups, add explicit entries for those types to `_orm.registry.type_annotation_map` before upgrading to SQLAlchemy 2.1.

✨ New Features

  • Refined ORM Annotated Declarative handling of PEP 695 type aliases, expanding the lookup scheme and adding support for generic aliases that reference `Annotated` constructs with `_orm.mapped_column()` configurations.
  • Added decorator `_orm.mapped_as_dataclass()` as a function‑based alternative to `_orm.registry.mapped_as_dataclass()` for better mypy PEP 681 support.

🐛 Bug Fixes

  • Unblocked automatic greenlet installation for Python 3.14 now that wheels are available.
  • Fixed caching issue in `_orm.with_loader_criteria()` where cached bound parameter values were incorrectly reused with `_sql.CompoundSelect` constructs.
  • Implemented initial free‑threaded Python support and fixed two concurrency issues: initialization of the `.c` collection on a `FromClause` and synchronization of the pool `first_connect` event.
  • Improved `UpdateBase.returning()` to correctly set up the `.c` collection for derived statements such as CTEs, fixing RETURNING clause expression issues.
  • Fixed `_schema.MetaData.reflect()` to forward dialect‑specific keyword arguments (e.g., `oracle_resolve_synonyms`) to the `_engine.Inspector` methods.
  • Corrected typing for `Session.execute()` so it now returns `Result` in all cases; use `typing.cast()` when a `CursorResult` is required.
  • Generalized asyncpg dialect terminate logic for reuse in aiomysql and asyncmy dialects.
  • Fixed enum array column parsing in PostgreSQL dialect to correctly handle NULL values by converting them to Python `None`.
  • Fixed `_sql.any_()` and `_sql.all_()` aggregation operators to coerce custom value types (e.g., Enums) correctly.
  • Fixed SQLite table reflection for tables with `WITHOUT ROWID` or `STRICT` options that contain generated columns.
  • Improved asyncio cursor implementation for MSSQL to actively close drivers that require an awaitable `cursor.close()`.

🔧 Affected Symbols

_orm.registry.type_annotation_map_orm.with_loader_criteriaUpdateBase.returning_schema.MetaData.reflectSession.execute_orm.mapped_as_dataclass_sql.any__sql.all__split_enum_values

⚡ Deprecations

  • Recursive lookups of PEP 695 type aliases remain deprecated in 2.0 and will be disallowed in 2.1; add entries to `_orm.registry.type_annotation_map` to avoid future failures.
  • Implicit lookups of `NewType` types without an entry in `_orm.registry.type_annotation_map` remain deprecated and will be disallowed in 2.1.