Skip to content

Conversation

@mreid-tt
Copy link

When mapped-as-dataclass is enabled under SQLAlchemy 2.x, models that
declare a pre-existing table cannot undergo the dataclass transform,
and SQLAlchemy raises:

InvalidRequestError: ORM Annotated Dataclasses do not support a pre-existing 'table' element

This PR opts out of the dataclass transform for such models by setting
sa_dataclass = False early in init_subclass. This preserves the
global mapped-as-dataclass behavior while restoring compatibility for
explicit-table mappings.

This fixes the failures in tests/test_model_bind.py::test_explicit_table
under the dataclass-enabled matrix.

@mreid-tt mreid-tt closed this Oct 31, 2025
@mreid-tt mreid-tt deleted the fix/dataclass-explicit-table branch October 31, 2025 21:13
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant