From ac62021a90cbf5fbefb2e5fa2ce12b960d230c37 Mon Sep 17 00:00:00 2001 From: Sinity Date: Fri, 31 Jul 2026 16:27:10 +0200 Subject: [PATCH] fix(storage): restore literal_check deleted out from under live call sites Problem: PR #3458 (5798b3dd1, merged 2026-07-31) deleted `literal_check` from `archive_tiers/common.py` as an "uncalled generator", but `archive_tiers/index.py`'s `delegation_facts` DDL calls it twice (`mapping_state` and `result_status` CHECK clauses, built at module import time). The deletion broke `import polylogue.storage.sqlite.archive_tiers` on master -- and therefore ArchiveStore, the CLI, devtools, and every test that touches storage, i.e. essentially the whole toolchain. `devtools status` and any pytest collection that imports `polylogue.storage` failed outright before this fix. What changed: restored `literal_check` (and its `sql_string_literal` import) verbatim, with a docstring noting the deletion was based on a "zero call sites" audit that was wrong -- both call sites are plain `literal_check(...)` calls in index.py, not aliased or generated. Added back to `__all__`. Verification: `python3 -c "import polylogue.storage.sqlite.archive_tiers. index"` and `from ...archive import ArchiveStore` both succeed (previously ImportError). `devtools status` runs. `devtools test tests/unit/storage/test_archive_tiers_common.py tests/unit/archive/test_session_revision_membership.py` -- 48 passed. Found and fixed as a blocking prerequisite while investigating polylogue-oycw (the set-based revision-membership superset fix landed same-day in #3401/#3405); could not run devtools/tests at all until this regression was fixed. Co-Authored-By: Claude --- .../storage/sqlite/archive_tiers/common.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/polylogue/storage/sqlite/archive_tiers/common.py b/polylogue/storage/sqlite/archive_tiers/common.py index c9cc127e80..487a02a980 100644 --- a/polylogue/storage/sqlite/archive_tiers/common.py +++ b/polylogue/storage/sqlite/archive_tiers/common.py @@ -6,6 +6,7 @@ PolylogueStrEnum, nullable_sql_check_in, sql_check_in, + sql_string_literal, ) @@ -14,6 +15,29 @@ def check(column: str, enum_type: type[PolylogueStrEnum]) -> str: return sql_check_in(column, enum_type) +def literal_check(column: str, *values: str) -> str: + """Return a non-null ``column IN (...)`` expression for explicit literals. + + Mirrors :func:`check`, but for closed vocabularies expressed as + ``typing.Literal`` aliases rather than ``PolylogueStrEnum`` types. Callers + expand the alias with ``typing.get_args`` at the call site so this helper + stays free of an ``insights`` import inside the storage substrate. + + Restored: PR #3458 deleted this as an "uncalled generator", but + ``archive_tiers/index.py``'s ``delegation_facts`` DDL calls it twice + (``mapping_state``, ``result_status`` CHECK clauses) -- the deletion + broke the import chain for the whole ``archive_tiers`` package (and + therefore ``ArchiveStore``, the CLI, and every test) on ``master`` as of + 5798b3dd1. The "zero call sites" audit was simply wrong; both call + sites are plain ``literal_check(...)`` calls, not aliased or generated. + Re-verify with a real grep before deleting again. + """ + if not values: + raise ValueError("literal_check requires at least one value") + rendered = ", ".join(sql_string_literal(value) for value in values) + return f"{column} IN ({rendered})" + + def nullable_check(column: str, enum_type: type[PolylogueStrEnum]) -> str: """Return a nullable enum CHECK expression.""" return nullable_sql_check_in(column, enum_type) @@ -89,6 +113,7 @@ def json_array_check(column: str, *, nullable: bool = False) -> str: "json_array_check", "json_check", "json_object_check", + "literal_check", "nullable_check", "order_check", ]