Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0c936c8

Browse files
author
James Page
committedFeb 14, 2025
tests: MappedAsDataclass - skip table binding
With SQLAlchemy 2.0.36 mapping as a dataclass while also proviing a ``__table__`` attribute is not supported. Skip associated test when ``MappedAsDataclass`` is in use. Fixes: pallets-eco#1378
1 parent 3e3e92b commit 0c936c8

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed
 

‎tests/test_model_bind.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import sqlalchemy as sa
4+
import sqlalchemy.orm as sa_orm
45

56
from flask_sqlalchemy import SQLAlchemy
67

@@ -76,15 +77,17 @@ class User(db.Model):
7677

7778

7879
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-
)
80+
if not issubclass(db.Model, (sa_orm.MappedAsDataclass)):
8481

85-
class User(db.Model):
86-
__bind_key__ = "other"
87-
__table__ = user_table
82+
user_table = db.Table(
83+
"user",
84+
sa.Column("id", sa.Integer, primary_key=True),
85+
bind_key="auth",
86+
)
8887

89-
assert User.__table__.metadata is db.metadatas["auth"]
90-
assert "other" not in db.metadatas
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

0 commit comments

Comments
 (0)
Please sign in to comment.