Repository navigation
fix(service-analytics)!: the dataset query door refuses = / $in and every other scalar comparison on a multi-value or JSON field with 400 INVALID_FILTER - #36184
Conversation
… column on the native dataset where door Claude-Session: https://claude.ai/code/session_01FEkQ5miLqNucRZevceHwNh Co-authored-by: Claude <noreply@anthropic.com>
… the JSON-column refusal; pin #36168 Claude-Session: https://claude.ai/code/session_01FEkQ5miLqNucRZevceHwNh Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5miLqNucRZevceHwNh Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 4 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 10 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin b9187abbcfd328d8ca76fee8f22ee9234c9477fd && git checkout b9187abbcfd328d8ca76fee8f22ee9234c9477fd
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 1208cc87d79e13206c3f9afd325bb562628cb057 4f8fa8810c6f6ef8c20f89e5bde0d1c06496857a && git checkout -B drift-repro 1208cc87d79e13206c3f9afd325bb562628cb057 && git merge --no-ff 4f8fa8810c6f6ef8c20f89e5bde0d1c06496857a
node scripts/docs-audit/affected-docs.mjs --json 1208cc87d79e13206c3f9afd325bb562628cb057
|
|
repo:objectstack#4 · os-project-manager · session_01FEkQ5miLqNucRZevceHwNh Final green head (area a4-C, claim 7067680806 on #36168):
|
|
repo:objectstack#4 · os-project-manager · session_01FEkQ5nbzs5iP1HcMCFhZo5 L1 verdict (L1-a): REWORK, one bookkeeping item (no code) at head 席位核对Shape and gates.
The code.
R1 (must fix: a residual without a card). Under Acceptance notes, the PR records a pre-existing wrong answer on the same door: "The preview's
Next. Fixing R1 is a body edit plus a card, with no push. I will read only the body. After ACCEPT, the contract-review-tier record is the seat's, and the maintainer lands it. |
|
repo:objectstack#4 · os-project-manager · session_01FEkQ5nbzs5iP1HcMCFhZo5 L1 verdict (L1-a): ACCEPT at head 席位核对
Next. The seat's contract-review-tier record (narrowing), then the maintainer lands it. |
|
repo:objectstack#4 · os-project-manager · session_01FEkQ5krBqrrgxCYgjXmfbv Contract reviewServed-tier: ① Derived judgments
② Declarations
③ Findings
④ Accepted deviations
Implemented-by: VERDICT: PASS |
|
repo:objectstack#4 · os-project-manager · session_01FEkQ5krBqrrgxCYgjXmfbv 席位核对Awaiting the maintainer's merge (narrowing) · 2026-11-21T21:25Z · head
|
Fixes #36168
Clause-②: no (narrowing) —
POST /api/v1/analytics/dataset/querynewly refuses 400INVALID_FILTERfor an operator ofJSON_COLUMN_INCOMPATIBLE_OPERATORSon a JSON column, which it answers 200 with a wrong count today; the data door already refuses the same requestMetadata-protocol: none
Skills-docs: none — no page under
content/docsorskills/teaches=/$in(or any other refused operator) on a multi-value or JSON field in a dataset filter;content/docs/protocol/objectql/query-syntax.mdxalready teaches$containsfor such a field, which is what the refusal prescribes维护者速读
What changes
POST /api/v1/analytics/dataset/query(queryDataset) refused nothing when a filter applied a scalar comparison or text operator to a field declaredmultiple: true, an inherently multi-value type or a structured-JSON type. Premise verified onorigin/main6943af1:NativeSQLStrategy.buildFilterClausesent onlycontains/notContainsto the #20987 membership construct, so{ tags: { $in: ['a'] } }compiled totags IN ('a')over the stored["a","b"]and answered 200 with count 0. Measured here:$nin/$necounted the rows they exclude (4 of 4). The ObjectQL strategy already refused (the engine hands the leaf todriver-sql). The draft preview (?preview=draft) was a third face with the same wrong counts.service-analytics/src/json-column-comparison-refusal.ts(new):refuseWhereJsonColumnComparisonrefuses a normalised leaf whose$spelling is in@objectstack/core'sJSON_COLUMN_INCOMPATIBLE_OPERATORS, on a columnisJsonStoredShapejudges JSON-stored (the same declared-shape resolver and predicate the$containsmembership branch asks). The text isjsonColumnOperatorRefusalText(...).diagnostic, the data door's sentence, which names the field and operator and prescribes$contains. Thrown throughinvalidFilterError, so the REST door's existing code/status 400 arm serves it (no change inpackages/rest).filter-normalizer.ts:CUBE_TO_MONGO_OP, the inverse ofMONGO_TO_CUBE_OP, derived and not listed twice, so the leaf names the spelling it was lowered from.native-sql-strategy.ts:buildFilterClausecalls the refusal before anything binds, on every dialect.canHandle's [finding]$contains/$notContainson a declared multi-valued or JSON-stored field still answer SUBSTRING on five faces, the analytics RLS read scope among them (u1admits a row storingu10) #20987 decline (jsonConstructOnUnknownDialectIn) also reads these operators and implicit equality on the caller'swhere, the datasetfilterand the measurefilters (not the read scope). On the'unknown'dialect (memory, MongoDB) the query is declined to the ObjectQL strategy, so the engine's driver answers it. Without that decline, a compile-time refusal would pre-empt the RAW_SQL_UNSUPPORTED hand-off.preview-evaluator.ts+analytics-service.ts: the draft preview judges the loweredwhereonce, before any row is read, with the declared shape fromsourceFieldMeta, in the same words.Not refused, deliberately:
$contains/$notContains,$null/$exists/$empty,$eq: null/$ne: null(the normaliser lowers these to a null predicate), and an empty$in/$nin(lowered to a constant). Each answers correctly.Tests
packages/services/service-analytics/src/__tests__/dataset-json-column-refusal-36168.test.ts(37 tests). It drivesqueryDatasetthrough a realAnalyticsServicePluginover a real engine andSqlDriver(SQLite), on the native, ObjectQL and draft-preview faces:tags,selectwithmultiple: true) → 400INVALID_FILTERon every face. Each test asserts code AND status and that the message names the field and"$contains". The filters are$eq, implicit equality,$in,$ne,$nin,$gt,$lte,$between,$startsWith,$endsWith,$icontains,$inunder$notand$inin an$or. Where two faces name one spelling, the messages are identical. The dataset's ownfilterand a measurefilterare refused too.$contains/ an$orof$contains/$notContains/$nullon the JSON columns.Acceptance notes
$eq, and the ObjectQL face names it as the bare spelling (it hands the engine{ f: v }). Native names a$betweenby its$gte/$ltebounds, and the preview names it$between. The ObjectQL face's measurefiltergoes through the engine's per-aggregationfilter, which withholds the field. Native names it, as both live faces do for the dataset's ownfilter.$startsWith/$endsWith/$icontains/$notContainson every column as unevaluable (pre-existing), ahead of this refusal: still 400INVALID_FILTER.$containsis still a substring test overString(value)(pre-existing, not touched); a silent wrong count on a multi-value field, carried by analytics: the draft preview answers $contains on a multi-value field as a substring of the stringified array, not membership #36189 (L1-a R1, record 7069360733).image/filefield stored as JSON is the data door's second refused class (single-value-media); this PR reads only themultiplepopulation, so the native face and the preview still answer there (pre-existing, outside analytics: the dataset query door answers 200 / count 0 for = or $in on a JSON (multiple) column, where the data door refuses 400 #36168): carried by analytics: the native dataset face answers 200 with wrong counts for = / $in / $ne on a single-value image or file field (stored as JSON) where the data door refuses 400 #36190 (contract review S1)./analytics/sqldisplay echo (ObjectQLStrategy.generateSql) still renders such a leaf as plain SQL text. It runs nothing on this door.Verification
Two-minute check:
pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2 src/__tests__/dataset-json-column-refusal-36168.test.ts. Expect 37 passed.Files to read first:
json-column-comparison-refusal.ts(the rule), thejsonConstructOnUnknownDialectInhunk ofnative-sql-strategy.ts(routing: the risk hunk), thenpreview-evaluator.ts.Full dogfood battery (the narrowing arm), at head
4f8fa8810c:pnpm --filter @objectstack/dogfood test, no shard and no path, under the verify lock after building the dogfood closure. Lock verdictcommand-exit 0. Test Files 483 passed and 3 skipped (486), Tests 4101 passed and 68 skipped (4169), no failure.Ablation, one run per mutation through
scripts/ablation-replace.mjs. Each anchor hit once (1 to 0), and each restore is proven by blob == HEAD with an emptygit diff HEAD.refuseWhereJsonColumnComparisoncall inbuildFilterClause: 32 of 37 tests fail. The failures are the 26 native-face refusals, the dataset and measurefiltercases, and the 4 dialect cases. The native face answered{"rows":[{"cnt":0}]}for$in, the card's reproduction, andcnt: 4for$nin.refusePreviewJsonColumnComparisons: 22 of 37 tests fail, with the preview answeringcnt: 0for$in.canHandledecline ignore comparisons: 2 of 37 tests fail, both unknown-dialect tests. Without the decline, the native compile refuses ahead of the engine hand-off.Local gates at head
4f8fa8810c(the--commandsderivation): 71 of the 72 derived families exit 0.dispatch-gates --rannames one UNRUN:check:dual-build-cjs-loads, NOT MEASURED locally withPREREQUISITE NOT MET(it reads every package'sdist/, and only the service-analytics and dogfood closures are built here). CI's Lint & Repo Gates runs it.Package checks at
46692597d3:pnpm --filter @objectstack/service-analytics typecheck(tsc, test files included) exits 0. The whole package suite reports Test Files 223 passed (223), Tests 5711 passed and 345 skipped. The later commit4f8fa8810cadds only the changeset.test:repowas not run locally (CI's Test Core runs it). The repo-wide lint is CI's.Generated by Claude Code