From d89798186566bbabe5be09bd36b29233d6bc9e25 Mon Sep 17 00:00:00 2001 From: ThearchyHelios Date: Sun, 4 Oct 2026 02:35:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=81=E6=8D=AE=E6=8E=A5=E5=8F=A3=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=AD=A5=E9=AA=A4=E7=9A=84=20schema=5Fartifact?= =?UTF-8?q?=E3=80=81catalog=20=E5=8F=AA=E5=9C=A8=E8=BF=99=E6=9D=A1?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=AF=B9=E7=85=A7=E8=BF=87=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E6=97=B6=E6=89=8D=E5=8A=A0=EF=BC=9A=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E7=9B=AE=E5=BD=95=E7=9A=84=E6=BA=90=E3=80=81=E8=80=81?= =?UTF-8?q?=E5=BF=AB=E7=85=A7=E7=9A=84=E6=9F=A5=E8=AF=A2=E6=AD=A5=E9=AA=A4?= =?UTF-8?q?=E5=92=8C=E4=BB=A5=E5=89=8D=E4=B8=80=E5=AD=97=E4=B8=8D=E5=B7=AE?= =?UTF-8?q?=EF=BC=88=E6=9C=9F=204=20=E7=9A=84=E9=87=91=E6=A0=B7=E9=80=90?= =?UTF-8?q?=E5=AD=97=E6=AF=94=E5=AF=B9=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/evidence.py | 15 ++++++--------- backend/tests/test_evidence_query_catalog.py | 15 +++++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/backend/app/api/evidence.py b/backend/app/api/evidence.py index f2c9ae08..52afad10 100644 --- a/backend/app/api/evidence.py +++ b/backend/app/api/evidence.py @@ -999,20 +999,19 @@ def _catalog_of(snap: dict[str, Any]) -> dict[str, Any]: 数据源查询工具每次查询都把当时的表结构和数据目录冻结进表结构快照(tools/datasource._store_schema),SQL 检查 对照的就是这一版。面板上写「数据目录:入园记录 第 3 版」:事后目录改了、升了版本,看得出这次查询按的是哪一版。 - catalog 只列 SQL 用到、而且冻结了目录的表:[{table, label?, version}]。没有表结构快照的(合并查询、老快照、 - 没探查过结构的源)两个键都不加;有快照没目录的只给 schema_artifact。 + catalog 只列 SQL 用到、而且冻结了目录的表:[{table, label?, version}]。这条查询没对照过目录(合并查询、老快照、 + 没探查过结构或没有目录的源、表结构快照读不出来)时两个键都不加:步骤的形状和以前一字不差(期 4 的金样逐字比对)。 """ schema_id = snap.get("schema_artifact") if not isinstance(schema_id, str) or not schema_id: return {} - out: dict[str, Any] = {"schema_artifact": schema_id} try: schema = load(schema_id) - except Exception: # noqa: BLE001 - 读不出来:只给 id,不编版本 - return out + except Exception: # noqa: BLE001 - 读不出来:不编版本 + return {} frozen = schema.get("catalog") if isinstance(schema, dict) else None if not isinstance(frozen, dict) or not frozen: - return out + return {} from app.data.catalog import resolve_table_name listed: list[dict[str, Any]] = [] @@ -1024,9 +1023,7 @@ def _catalog_of(snap: dict[str, Any]) -> dict[str, Any]: label = ((entry.get("notes") or {}).get("label") or {}).get("value") listed.append({"table": key, **({"label": label} if isinstance(label, str) and label else {}), "version": entry.get("version")}) - if listed: - out["catalog"] = listed - return out + return {"schema_artifact": schema_id, "catalog": listed} if listed else {} #: 查询步骤里每条 SQL 检查结果交给界面的字段(data/sqlcheck.SqlCheck.as_dict 去掉 for_model) diff --git a/backend/tests/test_evidence_query_catalog.py b/backend/tests/test_evidence_query_catalog.py index 69df83e7..a40d30b7 100644 --- a/backend/tests/test_evidence_query_catalog.py +++ b/backend/tests/test_evidence_query_catalog.py @@ -83,12 +83,15 @@ async def test_the_query_step_names_the_catalog_version_it_was_checked_against() async def test_a_query_without_a_frozen_catalog_says_nothing_extra(): - query = {"columns": ["n"], "rows": [[4]], "row_count": 1, "truncated": False, "source": "scenic", - "sql": "SELECT COUNT(*) AS n FROM visits"} - qid = await put(query) - doc = {"catalog": {"Q1": {"kind": "query", "artifact": qid}}} - step = await api._query_step(qid, [(0, "n")], doc, _sealed({qid: {"node_id": "fetch"}}), api._Masks()) - assert "catalog" not in step and "schema_artifact" not in step + """没对照过目录的查询(老快照、没有目录的源):步骤的形状和以前一字不差(期 4 的金样逐字比对)。""" + schema_id = await put({"source": "scenic", **_schema_cache()}, kind="schema_snapshot") + for extra in ({}, {"schema_artifact": schema_id}): + query = {"columns": ["n"], "rows": [[4]], "row_count": 1, "truncated": False, "source": "scenic", + "sql": "SELECT COUNT(*) AS n FROM visits", **extra} + qid = await put(query) + doc = {"catalog": {"Q1": {"kind": "query", "artifact": qid}}} + step = await api._query_step(qid, [(0, "n")], doc, _sealed({qid: {"node_id": "fetch"}}), api._Masks()) + assert "catalog" not in step and "schema_artifact" not in step def test_frozen_catalog_keeps_rejected_relation_ids_without_their_content():