diff --git a/backend/tests/test_db_portable.py b/backend/tests/test_db_portable.py index d56c206d..6374077f 100644 --- a/backend/tests/test_db_portable.py +++ b/backend/tests/test_db_portable.py @@ -58,6 +58,24 @@ def test_checkpoint_tables_do_not_clash_with_app_tables(): assert created & set(Base.metadata.tables) == set() +def test_no_query_compares_sorts_or_groups_a_whole_json_column(): + """PostgreSQL 的 json 没有相等运算符:整列做 ==、!=、in_、DISTINCT、ORDER BY、GROUP BY 都会报错(SQLite 不报)。 + 按里面某个键筛选走 db/portable 的 json_eq 等。扫一遍应用代码里「模型.JSON列」后面跟着这几样的写法。""" + from pathlib import Path + + from sqlalchemy import JSON + + columns = sorted({f"{m.class_.__name__}.{a.key}" for m in Base.registry.mappers for a in m.column_attrs + if isinstance(a.columns[0].type, JSON)}) + names = "|".join(re.escape(c) for c in columns) + bad = re.compile(rf"(?