From f0c34d790df0a1d5993c1605fd72082f1d79c5d2 Mon Sep 17 00:00:00 2001 From: ThearchyHelios Date: Mon, 19 Oct 2026 10:28:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=88=E7=9D=80=20PostgreSQL=20=E7=9A=84=20j?= =?UTF-8?q?son=20=E5=88=97=EF=BC=9A=E6=89=AB=E5=BA=94=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=87=8C=E5=AF=B9=E6=95=B4=E4=B8=AA=20JSON=20?= =?UTF-8?q?=E5=88=97=E5=81=9A=20=3D=3D=E3=80=81!=3D=E3=80=81in=5F=E3=80=81?= =?UTF-8?q?DISTINCT=E3=80=81ORDER=20BY=E3=80=81GROUP=20BY=20=E7=9A=84?= =?UTF-8?q?=E5=86=99=E6=B3=95=EF=BC=88json=20=E6=B2=A1=E6=9C=89=E7=9B=B8?= =?UTF-8?q?=E7=AD=89=E8=BF=90=E7=AE=97=E7=AC=A6=EF=BC=8CSQLite=20=E4=B8=8D?= =?UTF-8?q?=E6=8A=A5=E3=80=81PostgreSQL=20=E6=8A=A5=E9=94=99=EF=BC=89?= =?UTF-8?q?=EF=BC=8C=E4=B8=80=E5=A4=84=E9=83=BD=E4=B8=8D=E8=AE=B8=E6=9C=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/tests/test_db_portable.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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"(?