1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-12 18:59:50 +03:00
aports/community/py3-flask-sqlalchemy/tests-skip-table-binding.patch
mio 49e6a3f8d0 community/py3-flask-sqlalchemy: fix failing tests
Resolves build failure due to failed tests with sqlalchemy >= 2.0.36.

Example error:

```
___________________________ test_explicit_table[db2] ___________________________

[...]

self = <sqlalchemy.orm.decl_base._ClassScanMapperConfig object at 0xf4a06828>

[...]

        # can't create a dataclass if __table__ is already there. This would
        # fail an assertion when calling _get_arguments_for_make_dataclass:
        # assert False, "Mapped[] received without a mapping declaration"
        if "__table__" in self.cls.__dict__:
>           raise exc.InvalidRequestError(
                f"Class {self.cls} already defines a '__table__'. "
                "ORM Annotated Dataclasses do not support a pre-existing "
                "'__table__' element"
            )
E           sqlalchemy.exc.InvalidRequestError: Class <class 'test_model_bind.test_explicit_table.<locals>.User'> already defines a '__table__'. ORM Annotated Dataclasses do not support a pre-existing '__table__' element

/usr/lib/python3.12/site-packages/sqlalchemy/orm/decl_base.py:1074: InvalidRequestError
```
2025-05-08 03:55:27 +00:00

40 lines
1.2 KiB
Diff

Patch-Source: https://github.com/pallets-eco/flask-sqlalchemy/pull/1384
---
From c3a9137434b2fbcd03d4711dc7211f0889a55c15 Mon Sep 17 00:00:00 2001
From: James Page <james.page@canonical.com>
Date: Fri, 14 Feb 2025 09:31:37 +0000
Subject: [PATCH] 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 | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tests/test_model_bind.py b/tests/test_model_bind.py
index 7c633c83..e31d33b2 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,6 +78,9 @@ class User(db.Model):
def test_explicit_table(db: SQLAlchemy) -> None:
+ if issubclass(db.Model, (sa_orm.MappedAsDataclass)):
+ pytest.skip("Explicit table binding with mapped dataclasses not supported")
+
user_table = db.Table(
"user",
sa.Column("id", sa.Integer, primary_key=True),