Skip to content

Commit 3810fe1

Browse files
author
James Page
committed
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: pallets-eco#1378
1 parent 3e3e92b commit 3810fe1

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

Diff for: tests/test_model_bind.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__ import annotations
22

3+
import pytest
34
import sqlalchemy as sa
5+
import sqlalchemy.orm as sa_orm
46

57
from flask_sqlalchemy import SQLAlchemy
68

@@ -76,15 +78,18 @@ class User(db.Model):
7678

7779

7880
def test_explicit_table(db: SQLAlchemy) -> None:
79-
user_table = db.Table(
80-
"user",
81-
sa.Column("id", sa.Integer, primary_key=True),
82-
bind_key="auth",
83-
)
84-
85-
class User(db.Model):
86-
__bind_key__ = "other"
87-
__table__ = user_table
88-
89-
assert User.__table__.metadata is db.metadatas["auth"]
90-
assert "other" not in db.metadatas
81+
if not issubclass(db.Model, (sa_orm.MappedAsDataclass)):
82+
user_table = db.Table(
83+
"user",
84+
sa.Column("id", sa.Integer, primary_key=True),
85+
bind_key="auth",
86+
)
87+
88+
class User(db.Model):
89+
__bind_key__ = "other"
90+
__table__ = user_table
91+
92+
assert User.__table__.metadata is db.metadatas["auth"]
93+
assert "other" not in db.metadatas
94+
else:
95+
pytest.skip("Explicit table binding with mapped dataclasses not supported")

0 commit comments

Comments
 (0)