Repository navigation
fix(service-analytics): a declared measure behind the cube's own qualifier in a filter answers what its bare spelling answers - #31899
Conversation
…a filter reads the measure A filter member spelled CUBE.total, DATASET.total or OBJECT.total, where total is a declared measure, now resolves on both strategies the way the where gate already read it: declared dimensions, then declared measures, before the synthetic relation traversal. It compiles exactly as bare total does instead of as a join through a hop named for the cube. Claude-Session: https://claude.ai/code/session_01ADHkmPssfuxFFm8in9oCRq Co-authored-by: Claude <noreply@anthropic.com>
…r in a filter on every face Claude-Session: https://claude.ai/code/session_01ADHkmPssfuxFFm8in9oCRq Co-authored-by: Claude <noreply@anthropic.com>
…ilter Claude-Session: https://claude.ai/code/session_01ADHkmPssfuxFFm8in9oCRq Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmPssfuxFFm8in9oCRq Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check7 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run. 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 85ca69816115cadbb54270dfd8843c0125e14ccb && git checkout 85ca69816115cadbb54270dfd8843c0125e14ccb
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin a15b544d542fa3eda258732999778b69613618bd 2c2c10a03ff72ab732aeebda7dc1848363239004 && git checkout -B drift-repro a15b544d542fa3eda258732999778b69613618bd && git merge --no-ff 2c2c10a03ff72ab732aeebda7dc1848363239004
node scripts/docs-audit/affected-docs.mjs --json a15b544d542fa3eda258732999778b69613618bd |
|
domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM 维护者速读
席位核对 — ACCEPT · domain:server#2 · Head-sha
|
…ts related object lacks answers 400 INVALID_FIELD, not a database error (objectstack-ai#31943) <!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi99NaHA8uVthXXC139JxE9ZB)_ Fixes objectstack-ai#31881 Clause-②: no — a 500 becomes the 400 the same input already gets on the compiled-dataset path; nothing served changes, and no export, error code or status is added. Metadata-protocol: none ## 维护者速读 - 改了什么:手写分析立方上,按关联对象并不存在的字段查询(如 `vendor.nope`,或 vendor 没有 region 时的 `vendor.region`),现在在编译前被拒绝为 400 字段无效,并点名成员和关联对象;以前原生 SQL 策略会拼出 JOIN 后报 500 数据库错误。 - 为什么改:同样的输入走编译后的数据集路径早就被同一道关联字段闸门拒为 400;手写立方路径因为没有 include 白名单而跳过了这道闸门。现在两条路径问的是同一道闸门、同一句话。 - 风险与回滚:只放宽闸门的一个提前返回条件,并在调用处传入原生策略本来就执行的白名单;存在的关联字段照常关联和筛选。只动 `@objectstack/service-analytics`,回滚即 revert 本 PR。 - 先看:`packages/services/service-analytics/src/analytics-service.ts` 的 `assertRelationshipColumnsExist`(`!allowed` 不再提前返回)与 `callCtx` 中它的调用处(改传 `getAllowedRelationships`);测试 `dotted-dimension-unbacked-join-parity.test.ts` 末尾新增的 `[objectstack-ai#31881]` 块。 - 两分钟验证:`pnpm --filter @objectstack/service-analytics exec vitest run src/__tests__/dotted-dimension-unbacked-join-parity.test.ts`,应见 24 个用例全绿,其中末尾 3 个是本卡新加的。 - 需要你做的:无,席位落地。 ## What changes `packages/services/service-analytics/src/analytics-service.ts`, one gate, no second copy of the rule: - **The gate** is `AnalyticsService.assertRelationshipColumnsExist` (objectstack-ai#28558), the related-column gate the compiled-dataset path already asks in `callCtx`. It returned early when `allowed` (the compiled dataset's `allowedRelationships`) was `undefined`, which is every hand-authored cube. It now runs on every cube; the `include`-backed check inside it (`unbackedRelationshipPath`) runs only when there is an allowlist. - **The call site in `callCtx`** passes `reads.getAllowedRelationships(query.cube)`, the allowlist the native strategy itself enforces for that cube (`cubeReads`: a compiled dataset's `include`, else the configured `getAllowedRelationships` hook, else none). So a compiled dataset gets exactly the set it got before, and on a hand-authored cube with the legacy hook a path the hook does not back keeps the strategy's own `DATASET_INVALID`, as an unbacked path keeps `assertDimensionJoinsBacked`'s refusal on the dataset path. `assertDimensionJoinsBacked` and the draft-preview call site are unchanged. - **The refusal** is the gate's own: `INVALID_FIELD` / 400 via `invalidMemberError`, `member` / `param` / `cube` plus `field` and `object`, in the dataset path's sentence ("Filter member 'vendor.nope' on cube 'CUBE' reads field 'nope' through relationship path 'vendor', which object 'VENDOR' does not have. …"). No new code, status or envelope. Reach of the gate (seat ruling 3), measured on `80c4c9a2` and on the fix with the same harness: | Input on a hand-authored cube | Native before | Native after | Engine-aggregate before | Engine-aggregate after | |:--|:--|:--|:--|:--| | `vendor.nope` / `vendor.region` as a `where` leaf | 500 `DATABASE_ERROR` | 400 `INVALID_FIELD` (gate) | 400 `INVALID_FIELD` (cross-object filter refusal) | 400 `INVALID_FIELD` (gate) | | … as a dimension | 500 `DATABASE_ERROR` | 400 (gate) | 400 `INVALID_FIELD` (engine group-by guard) | 400 (gate) | | … as a windowed time dimension | 500 `DATABASE_ERROR` | 400 (gate) | 400 `INVALID_FIELD` (cross-object bucket refusal) | 400 (gate) | | … as a bucketed time dimension | 400 `INVALID_FIELD` (cross-object bucket refusal) | 400 (gate) | same as native | 400 (gate) | | `supplier.region` / `supplier.since` (column exists) | served | served, unchanged | unchanged | unchanged | | `nope.region` (no relationship field `nope` on the cube's object) | 500 `DATABASE_ERROR` | unchanged | 400 (its own refusals) | unchanged | | a cube whose `sql` is a statement (`SELECT * FROM deal`), `vendor.*` | 500 `DATABASE_ERROR` | unchanged | 400 / 404 `OBJECT_NOT_FOUND` | unchanged | - **Unknown hop** (`nope.region`): the hop resolver names an object called `nope` (the alias tier), the field probe has no answer for it, and the gate stands down, as it does on the dataset path. The dataset path refuses this input through a different gate (`assertDimensionJoinsBacked`, "traverses relationship path 'nope', which the dataset does not declare in its include"), which judges the `include` a hand-authored cube does not have; the related-column gate itself never refuses it. So per ruling 3 it keeps its native answer (500); listed in open questions. - **Raw `sql` cube**: the gate needs the cube's object name and stands down (`BARE_IDENTIFIER`), unchanged. - **Engine-aggregate face**: the same inputs were already 400 `INVALID_FIELD`; they now get the gate's sentence (naming the member and the related object) in place of three different ones. ## Tests New top-level `describe('[objectstack-ai#31881] …')` at the end of the shared objectstack-ai#28258 harness, `src/__tests__/dotted-dimension-unbacked-join-parity.test.ts` (real SQLite, `AnalyticsServicePlugin` on both strategies, a hand-authored cube named apart from its object, no allowlist): - `vendor.nope` and `vendor.region` (vendor has no `region`) answer 400 `INVALID_FIELD` on the native strategy as a `where` leaf, a dimension and a windowed time dimension: `code`, `status`, `param`, `member`, `field` and `object`. - On both strategies the cube's refusal message equals the compiled dataset's refusal for the same member (`include: ['vendor', 'supplier']`), with only the cube name differing. - CONTROL: `supplier.region` still joins and filters (`{region: emea, count: 2}`) and groups (`apac: 2`, `emea: 1`) on the native strategy. - objectstack-ai#31878's and objectstack-ai#31899's pins in the same file: unedited and green (24/24). **Forced test edit** (one): `src/__tests__/field-read-admission-gate.test.ts`, "judges only names the object's field list carries, and every name when that list is unavailable". Its first leg pinned a hand-authored cube query with `owner.not_a_field` (a related column the object's field list does not carry) EXECUTING on the native strategy. That is the input this card now refuses, so the leg now expects 400 `INVALID_FIELD` naming `owner.not_a_field` / `fr_owner` / `not_a_field` and nothing executed. Its claim (the read gate answers no 403 for an unlisted name) still holds; the second leg (no field list ⇒ 403) is unedited. <details><summary>Red on main, then ablation (mutation landed via scripts/ablation-replace.mjs; tests import package source, no dist leg)</summary> - **Red on main**: `analytics-service.ts` restored to the `80c4c9a2` blob (`584d6803`), `-t 31881`: 2 failed | 1 passed (the CONTROL). `AssertionError: where vendor.nope: The database refused to run a raw statement. … expected 'DATABASE_ERROR' to be 'INVALID_FIELD'`; `native vendor.nope: … expected 'DATABASE_ERROR' to be 'INVALID_FIELD'`. Restored: blob == HEAD. - **Ablation, skip the gate on the cube path** (`if (!probe || !cube) return;` → `if (!probe || !cube || !allowed) return;`, i.e. main's early return): `ok mutation landed: anchor 1 -> 0, blob 9bba336 -> a829f3584788`. Whole harness file: 2 failed | 22 passed (24), the two objectstack-ai#31881 400 pins back to `DATABASE_ERROR` (500); every objectstack-ai#28258 / objectstack-ai#31842 / objectstack-ai#31880 pin green. `ok restored: blob == HEAD (9bba336) and git diff HEAD is empty`. </details> ## Acceptance notes - The bucketed time-dimension row reads "ObjectQLStrategy cannot bucket a cross-object time dimension" on the NATIVE face on `main` for every dotted time dimension, `supplier.since` included (an existing column). That is the native strategy delegating cross-object bucketing (`cross-object-rebucket.ts`), not this card; recorded only. ## Verification Head `5be116d2` (fix `c8a7bf76`, changeset `ec72a669`, forced test edit `2ecf02ad`, merge of `origin/main` `6180c874`). - `pnpm --filter @objectstack/service-analytics test` on `5be116d2`, after `turbo run build --filter='./packages/**'` (81/81): Test Files 214 passed (214), Tests 5155 passed, 332 skipped. `typecheck` (`tsc --noEmit`) exit 0. Lock VERDICT command-exit 0. - Harness file alone on `2ecf02ad`: 24/24. - Lint: root `npx eslint --no-inline-config` on the three touched source/test files, exit 0 (the package has no `lint` script). `node scripts/check-nul-bytes.mjs` OK. - Gates: `dispatch-gates --commands` on `5be116d2` derives 69 families (the same 69 as on `2ecf02ad`); all 69 run on `5be116d2`, each exit 0. `--ran` reconciliation: "69 derived famil(ies) accounted for — 69 run, 0 NOT-MEASURED". Round 1 on `2ecf02ad`: 69/69 exit 0 after the teardown self-test's pinned fixture was fetched (first attempt exit 3, the shallow-clone prerequisite). - `main` moved 4 commits after the merge (`73bfe10e`); none touches `service-analytics` or this changeset. - Dogfood battery: n/a (no `!` in the title, no `(narrowing)` arm). --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmPfkQkDAAzanWLnAyz)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
Requested by Steve · project thread
Fixes #31880
Clause-②: no
Metadata-protocol: none
维护者速读
orders.total,total是已声明的度量)时,两种查询策略现在先查已声明的维度、再查已声明的度量,然后才当关联路径处理,与入口校验的读法一致;结果与只写total完全相同(同一条 SQL、同样的行)。DATASET_INVALID,手写立方体直接 500,引擎策略报跨对象筛选拒绝;只写total却正常(main 上实测)。vendor.total)行为不变,有对照测试钉住。回滚即还原本 PR。packages/services/service-analytics/src/cube-member-key.ts(新的declaredCubeFilterMember),然后两个策略里的lookupFilterMember/lookupCubeFilterMember。pnpm --filter @objectstack/service-analytics exec vitest run src/__tests__/dotted-dimension-unbacked-join-parity.test.ts,预期 21 个全过;其中[#31880]四条在 main 上有两条红。What changes
cube-member-key.tsgainsdeclaredCubeFilterMember(cube, member): the declared member a FILTER spelling names across both bags, dimensions first, then measures (the orderdeclaredMemberEntry(…, 'any')already reads them in the where gate). The measure arm answers a bare spelling or a dotted one behind the cube's own qualifier (CUBE.total,OBJECT.total); a dotted spelling behind any other first segment that names no declared dimension stays a relationship path exactly as fix(service-analytics)!: a dotted member like vendor.region no longer filters the base field of the same name #31878 left it.resolveFieldSqlandresolveStorageTargetread the filter member through a newlookupFilterMember(that helper, else the synthetic traversal). ObjectQL:resolveCubeFieldName(…, 'any')andresolveStorageTargetread it through the module-level twinlookupCubeFilterMember. The dimension-only and measure-only readings are unchanged.totaldoes on each strategy today: a row-level predicate on the measure's column (WHERE amount > ?native;where: { amount: { $gt } }to the engine aggregate). The qualified spelling now produces the byte-identical statement / aggregate call.resolveStorageTargetno longer keeps themember.split('.').slice(1).join('.')fallback its native twin dropped: an undeclared member is the member itself on both; (b) the helper module's jsdoc no longer claims to be the rule for every reader: it names the two measure readers that resolve by tail (resolveMeasureAggregation's alias arm,assertMeasureFields' qualifier strip) and whymintableMeasureKeykeeps them unreachable for a dotted non-qualifier spelling; (c) the draft preview face is pinned forDATASET.total(it accepts aruntimeFilterand answers it exactly astotal).Tests
A new top-level
describe('[#31880] …')in the existing real-SQLite harnessdotted-dimension-unbacked-join-parity.test.ts(shared-harness rule), with the engine'sexecute/aggregatewrapped so each pin compares what was SENT as well as the rows:DATASET.totalandOBJECT.totalin aruntimeFilteranswer exactly whattotalanswers (rows and statement), native and ObjectQL. RED on main.CUBE.totalandOBJECT.totalin awhereanswer exactly whattotalanswers, both strategies. RED on main.DATASET.totalexactly astotal(green on main too: the preview already reads members through the gate's lookup; pinned per review nit 4).vendor.total(first segment not the cube's own) is still refusedINVALID_FIELD/ 400 "traverses relationship path 'vendor'" on both strategies through a dataset, and refused as a cross-object filter by the engine face on a hand-authored cube.No existing test is edited; #31878's eight pins run unedited and green.
Acceptance notes
mainac8fede8before writing code (seat ruling 1), filter{ MEMBER: { $gt: 5 } }:main ac8fede answers
totalDATASET.totalOBJECT.totalCUBE.total(hand-authored)WHERE amount > ?, 2 rowsDATASET_INVALID/ 400 join not backedDATASET_INVALID/ 400 join not backedWHERE amount > ?, 2 rowsDATABASE_ERROR/ 500 (self-join)DATABASE_ERROR/ 500 (join to a table named for the cube)where: { amount: { $gt: 5 } }, 2 rowsINVALID_FIELD/ 400 cross-object filterINVALID_FILTER/ 400 (engine has no such column)INVALID_FILTER/ 400INVALID_FIELD/ 400 cross-object filterOn this branch every qualified cell answers the bare cell's statement and rows byte-for-byte.
declaredMemberEntry(…, 'any')) is unchanged. For a dotted spelling NOT behind the own qualifier it still reads a flat or verbatim measure key, where the strategies hand that spelling to the traversal tier; per seat ruling 2 that half keeps fix(service-analytics)!: a dotted member like vendor.region no longer filters the base field of the same name #31878's behaviour exactly and is not moved here (no first-party measure key mints one:mintableMeasureKey).an order keyamong narrowed positions). It is a wording fix to an existing, unreleased changeset, which the delta does not name; left for the seat.Verification
Head
2c2c10a0(3e83c779+ merge oforigin/maina15b544d5; the merge touches noservice-analyticsfile).Red first, ablation
git restore --source=ac8fede8of the three source files, test kept):Tests 2 failed | 19 passed (21), the two failing being pins 1 and 2 ([NativeSQLStrategy] join "os31880_deals" is not backed …;DATABASE_ERROR … no such table: os31880_cube). Restored withgit checkout HEAD --,git diff HEADempty.scripts/ablation-replace.mjs:cube-member-key.tsmeasure arm replaced byundefined(anchor 1 → 0, blob0edd12a8→8ae80de1):Tests 2 failed | 19 passed (21), pins 1 and 2 red; restored, blob == HEAD,git diff HEADempty. Tests import the package source, so no dist leg.Package and gates
pnpm --filter @objectstack/service-analytics test && … typecheckon3e83c779:Test Files 214 passed (214),Tests 5152 passed | 332 skipped;tsc --noEmitexit 0 (lock VERDICT command-exit 0).--no-inline-config, the package has nolintscript) on the four touched source/test files: exit 0.objectqlrebuilt, the harness pluscube-qualified-measure-filter.test.ts:Tests 28 passed (28).dispatch-gates --commands: 66 families on3e83c779, all exit 0;--ranreconciliation: 66 derived, 66 run, 0 NOT-MEASURED, 0 UNRUN. Re-run on2c2c10a0: see the report comment on the card.!, no(narrowing)arm).Human Minimum
packages/specholds no runtime logic (not touched).main, one pull request..changeset/31880-qualified-measure-filter.mdwith both declaration lines.packages/specnot touched.Generated by Claude Code