From: James Page Date: Fri, 14 Feb 2025 09:31:37 +0000 Subject: tests: MappedAsDataclass - skip table binding With SQLAlchemy 2.0.36 mapping as a dataclass while also providing a ``__table__`` attribute is not supported. Skip associated test when ``MappedAsDataclass`` is in use. Fixes: #1378 --- tests/test_model_bind.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tests/test_model_bind.py b/tests/test_model_bind.py index 7c633c8..6f1c602 100644 --- a/tests/test_model_bind.py +++ b/tests/test_model_bind.py @@ -1,6 +1,8 @@ from __future__ import annotations +import pytest import sqlalchemy as sa +import sqlalchemy.orm as sa_orm from flask_sqlalchemy import SQLAlchemy @@ -76,15 +78,18 @@ def test_explicit_metadata(db: SQLAlchemy) -> None: def test_explicit_table(db: SQLAlchemy) -> None: - user_table = db.Table( - "user", - sa.Column("id", sa.Integer, primary_key=True), - bind_key="auth", - ) - - class User(db.Model): - __bind_key__ = "other" - __table__ = user_table - - assert User.__table__.metadata is db.metadatas["auth"] - assert "other" not in db.metadatas + if not issubclass(db.Model, (sa_orm.MappedAsDataclass)): + user_table = db.Table( + "user", + sa.Column("id", sa.Integer, primary_key=True), + bind_key="auth", + ) + + class User(db.Model): + __bind_key__ = "other" + __table__ = user_table + + assert User.__table__.metadata is db.metadatas["auth"] + assert "other" not in db.metadatas + else: + pytest.skip("Explicit table binding with mapped dataclasses not supported")