File: tests-MappedAsDataclass-skip-table-binding.patch

package info (click to toggle)
flask-sqlalchemy 3.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 832 kB
  • sloc: python: 2,909; makefile: 27; sh: 14
file content (58 lines) | stat: -rw-r--r-- 1,751 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
From: James Page <james.page@canonical.com>
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")