You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f159aaa
Browse filesBrowse the repository at this point in the historyBrowse files
fix(service-analytics)!: a dotted member like vendor.region no longer filters the base field of the same name (#31878)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9EMQuDus5tHtakmfkN4PXrg)_Fixes#31842
Clause-②: no (narrowing)
Metadata-protocol: none
## 维护者速读
- 改了什么:分析查询里带点的成员(如筛选
`vendor.region`)只在第一段是本数据集/本对象名时才按本对象字段解析;否则一律按关联路径处理(未声明 include
就明确拒绝,已声明就筛关联对象的字段)。校验门和两种执行策略共用同一条规则。
- 为什么改:以前只要最后一段和本对象某个字段同名,`vendor.region` 就会悄悄按本对象自己的 region
筛选,图表数字是错的,且没有任何提示。
- 风险与回滚:属于收窄:原来"答错"的写法现在会被拒(INVALID_FIELD/400)或改为筛关联字段;一方代码里没有这种写法。回滚即
revert 本 PR。
-
先看:`packages/services/service-analytics/src/cube-member-key.ts`(唯一规则)、`analytics-service.ts`
的 `declaredMemberEntry`、两个策略的 `lookupMember`。
- 两分钟验证:`pnpm --filter @objectstack/service-analytics exec vitest run
src/__tests__/dotted-dimension-unbacked-join-parity.test.ts`,预期 17
个全绿(其中 8 个是本卡新增)。
- 需要你做的:无,席位落地。
## What changes
One rule for which declared cube member a spelling names, in a new
module `cube-member-key.ts` (`declaredCubeMemberKey`, not exported from
the package root), read by every resolver that used to carry its own
copy:
- the door's gates: `declaredMemberEntry` in `analytics-service.ts` (the
where gate, the dimension gate, the include gate, the field-read
admission, the preview column map);
- `NativeSQLStrategy.lookupMember` and `ObjectQLStrategy`'s
`lookupCubeMember`;
- the structured-JSON door's `measureEntryOf` (the same lookup for
measures; see Acceptance notes).
A spelling names a declared key verbatim (a declared dotted key
included), behind the cube's own qualifier (CUBE.region, or
OBJECT.region where OBJECT is the bare object the cube's `sql` reads),
or through an underscore-flattened key ONLY when that key's own `sql` is
the same relationship path. The bare-tail arm (`if (bag[tail]) return
bag[tail]`), which made the `first === cube.name` arm above it dead, is
gone from all four copies. Any other dotted member is a relationship
path: the dimension tier hands it to the join machinery, and on a
compiled dataset the existing include gate (or the existing
related-column gate) answers. No error code, envelope or export is
added.
The three undeclared fallbacks that read `member.split('.')[1]` as a
base column (`resolveFieldSql`, `resolveDimensionSql`,
`resolveCubeFieldName`) and the `split('.').slice(1)` one in
`resolveStorageTarget` now return the member itself. Measured: they were
unreachable for a dotted member, because the dimension lookup answers
every dotted member first (a declared key, or the synthetic traversal),
so the only path into them was a bare member; `resolveCubeFieldName`'s
could be reached dotted only with kind `measure`, which no caller
passes.
Seat ruling 3 (flat keys): nothing in the package MINTS a flat key.
`inferCubeFromQuery` mints a dotted member verbatim, and the dataset
compiler keys a dimension by its authored `name`. A flat key is authored
only; `skills/objectstack-ui/rules/dashboards.md` teaches
`account_industry` with `sql: 'account.industry'`, which names the
related field and still answers `account.industry`. A flat key over a
base column (a dataset dimension `vendor_region` over `region`) no
longer answers `vendor.region`.
## Tests
`dotted-dimension-unbacked-join-parity.test.ts` (the existing
real-SQLite harness for dotted members on both strategies) gains one
top-level `describe` with its own fixture: a deal with its own `region`,
a `vendor` lookup to an object with no `region`, and a `supplier` lookup
to one that has it (the supplier's region disagrees with the deal's on
every row, so the answer shows which column was read). Eight pins:
1. `vendor.region` through no include: refused `INVALID_FIELD` / 400,
param `where`, on both strategies. RED on main (served the base filter).
2. `vendor.region` through a declared include to an object without
`region`: refused `INVALID_FIELD` / 400 on both. RED on main.
3. `supplier.region` through a declared include: native filters the
joined supplier column; the engine-aggregate face refuses it as it
refuses every related filter. RED on main (both served `[]`, the base
filter).
4. CONTROL: DATASET.region and OBJECT.region still filter the base
column on both. Green on main.
5. `vendor.region` beside a flat `vendor_region` over the BASE column:
refused on both. RED on main.
6. A flat `supplier_region` over `supplier.region` answers that spelling
with the related column. RED on main (the bare-tail arm caught it
first).
7. A hand-authored cube (`query`): native joins the supplier for
`supplier.region`; the engine face refuses `vendor.region`. RED on main.
8. CONTROL: a hand-authored cube still filters CUBE.region as the base
column on both. Green on main.
No existing test was edited.
<details><summary>Red on main, then green</summary>
Sources restored from `origin/main` `31ae944b` (tree only), the new pins
run, then restored from `HEAD` (`git diff HEAD` empty):
```
× refuses 'vendor.region' through no include on both strategies, instead of filtering the deal's own region
× refuses 'vendor.region' through a declared include to an object with no 'region' on both strategies
× filters the RELATED 'supplier.region' through a declared include, never the deal's own region
× refuses 'vendor.region' beside a flat key 'vendor_region' over the BASE column on both strategies
× a flat key 'supplier_region' over the related 'supplier.region' answers ... (named a CONTROL in that run; renamed after it went red)
× a hand-authored cube: 'supplier.region' joins the supplier on the native strategy, and the engine face refuses 'vendor.region'
Tests 6 failed | 11 passed (17)
```
On the fix: `Tests 17 passed (17)`.
</details>
<details><summary>Ablations (scripts/ablation-replace.mjs, anchor hit 1
to 0 and blob moved each time; restored, git diff HEAD empty)</summary>
| ablation | file | result |
|:--|:--|:--|
| A1 drop the first-segment guard (any first segment names the tail) |
`cube-member-key.ts` | 5 failed / 12 passed |
| A2 restore the bare-tail arm in `NativeSQLStrategy.lookupMember` only
| `native-sql-strategy.ts` | 2 failed / 15 passed (pins 3 and 7) |
| A3 restore the bare-tail arm in `lookupCubeMember` only |
`objectql-strategy.ts` | 2 failed / 15 passed (pins 3 and 7) |
| A4 let any flat key answer a dotted path | `cube-member-key.ts` | 1
failed / 16 passed (pin 5) |
The tests import the sources (`../plugin.js`), not a `dist/`, so no
build leg applies.
</details>
## Acceptance notes
- **Measured on main (seat ruling 1).** `origin/main` `31ae944b`, real
`SqlDriver` (SQLite), the engine's `execute` / `aggregate` recorded. A
dataset over a deal with its own `region` answered `runtimeFilter: {
'vendor.region': 'emea' }` with `[{ region: 'emea', total: 11 }]` on
both strategies: native ran `... WHERE region = ? ...`, the engine face
handed `where: { region: 'emea' }`, with and without `vendor` in the
include. `supplier.region: 'apac'` (supplier HAS `region`) served `[]`
on both, from the same base filter. A flat `vendor_region` over `region`
answered `vendor.region` the same way. A hand-authored cube through
`query` did too. An undeclared dotted member with no same-named member
(`supplier.name`) already reached the JOIN machinery on main (native
LEFT JOIN, include gate refusal when unbacked).
- **Clause-② (seat ruling 5).** `no (narrowing)`: `vendor.region` is now
refused where the related object lacks the column or the path is
undeclared, so not every such input resolves to a related field.
BREAKING banner, ADR-0087 disposition `not-required
(no-migration-prescription)`, and the full dogfood battery on the final
head below. First-party count of a dotted analytics member whose tail
names a base member: 0 (grepped `content/`, `examples/`, `skills/`,
`packages/qa/dogfood`; the three dotted `where` hits are ObjectQL
data-query docs, not analytics).
- **OBJECT qualifier kept beside CUBE.** Seat ruling 2 names only the
cube's own name. A compiled dataset is named for the dataset, and
OBJECT.region has always named its base field: the existing #28258
control and the #28691 preview map pin it. The rule treats the bare
object of the cube's `sql` as an own qualifier too. Raised as an open
question in the report.
- **Changeset remedy.** The delta asked for a FROM / TO line. The
ADR-0087 gate reads a FROM-TO label as a migration prescription and
refuses it beside `no-migration-prescription`, so the remedy is stated
in prose (spell it CUBE.region or region; a stored member is not
rewritten, because only its author knows which field it meant).
- **Files beyond the claim's surface.** `src/cube-member-key.ts` (new
module, the one rule, not exported from the package root) and
`src/structured-json-dimension-door.ts` (`measureEntryOf` carried the
same bare-tail copy for measures; same defect class, mechanical, no new
gate family).
- **Out of scope, reported to the seat.** (a) A CUBE-qualified MEASURE
in a dataset `where` (`DATASET.total`) is read by the gate as the
declared measure but compiled by both strategies as a join through a hop
named for the dataset (native `DATASET_INVALID` "join ... is not
backed", engine face the cross-object refusal), while bare `total`
serves. Pre-existing on main, unchanged here. (b) On a hand-authored
cube (no include gate), the native strategy answers `DATABASE_ERROR` /
500 for a related column the related object lacks (`vendor.nope` on
main; now `vendor.region` lands there too, instead of being served from
the wrong column). The dataset path refuses the same input
`INVALID_FIELD` / 400.
## Verification
Head `93e3a44a` (merge of `origin/main` `ef194d79`).
<details><summary>Local runs</summary>
- `pnpm --filter @objectstack/service-analytics test` on `93e3a44a`:
Test Files 214 passed (214), Tests 5148 passed, 332 skipped.
- `pnpm --filter @objectstack/service-analytics typecheck` on `93e3a44a`
(closure built with DTS): 0 errors.
- `eslint packages/services/service-analytics --no-inline-config`: exit
0.
- `node scripts/pm/dispatch-gates.mjs --commands`: 70 families, all run
with exit 0 recorded; `--ran` reconciliation: 70 derived, 70 run, 0
NOT-MEASURED (derived zero). After the merge the derivation is unchanged
and the diff-sensitive families (adr-0087 registration, changeset
no-major, empty changeset, closing-keyword parity, issue citations,
doc-authoring, nul-bytes, cross-package test inputs, test-source alias,
affected docs) were re-run: all exit 0.
- Full dogfood battery: `93e3a44a` · os-verify-lock VERDICT command-exit
0 · Test Files 441 passed, 3 skipped (444) · Tests 3662 passed, 42
skipped (3704) · no failures. (Also green on the pre-merge head
`21e229dc`, same counts.)
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmP7cP3t3ncc39aFhhx)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(service-analytics)!: a dotted member such as `vendor.region` no longer names a declared member by its tail alone, so a filter on a related field never silently filters the base field of the same name
6
+
7
+
Clause-②: no (narrowing) — a dotted analytics member (a `where` / `runtimeFilter` leaf, a dimension, a time dimension, an `order` key) whose first segment is neither the cube's name nor the object it reads, and which no member declares verbatim, is no longer resolved to the declared member named by its last segment. It is a relationship path: through a compiled dataset the `include` gate refuses an undeclared path, and the related-column gate refuses a column the related object lacks, both `INVALID_FIELD` / 400 as before; a declared path filters the related column. An underscore-flattened key (`vendor_region`) answers `vendor.region` only when its own `sql` is that same relationship path. Nothing is widened: no export of the package root, public member, error code or status is added.
8
+
Metadata-protocol: none
9
+
10
+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export or type of the package root changes: a query member that read the wrong column is answered as the relationship path it spells, with error codes and statuses already on the wire. There is nothing for a migration to rewrite and no tombstone. -->
11
+
12
+
**BREAKING** accept-set narrowing on the analytics query doors (`@objectstack/service-analytics`), for a dotted member whose last segment names a declared member while its first segment names neither the cube nor its object.
13
+
14
+
-**Before.** Measured on `main``31ae944b` with a real `SqlDriver`: a dataset over a deal that declares its own `region`, with a `vendor` lookup to an object that has no `region`, answered `runtimeFilter: { 'vendor.region': 'emea' }` with the deals whose OWN region is EMEA, on the native-SQL and the engine-aggregate strategies alike (`WHERE region = ?`), with or without `vendor` in the dataset's `include`. A `supplier.region` filter over a supplier that does have `region` filtered the deal's own `region` too, and so did `vendor.region` beside a dataset dimension `vendor_region` over the base `region`. A hand-authored cube answered the same way through `AnalyticsService.query`.
15
+
-**Now.** Without `vendor` in the `include`, `vendor.region` is refused `INVALID_FIELD` / 400 ("traverses relationship path 'vendor', which the dataset does not declare in its `include`"). With it, a related object that lacks `region` is refused `INVALID_FIELD` / 400 naming the related object, and one that has it is filtered on the joined column (the engine-aggregate strategy keeps refusing any related filter, as it does for every other one). On a hand-authored cube, which has no `include` gate, the native strategy joins the lookup as it does for any other related member: `supplier.region` filters the supplier's column, and a related object that lacks the column answers the database's refusal (`DATABASE_ERROR` / 500), the same answer `vendor.anything_missing` gets today. `<cube>.region` and `<object>.region` still name the declared `region`.
16
+
-**Who moves.** A query, dashboard filter or tool call that wrote `<lookup>.<field>` to mean the base object's own `<field>`: spell it `<cube>.<field>` or `<field>`. No first-party metadata in `content/`, `examples/`, `skills/` or the dogfood apps spells one.
17
+
18
+
**The remedy.** A member written `'vendor.region'` to mean the base object's own field is spelled `'<cube>.region'` or `'region'` instead. A stored member is not rewritten for you: whether it meant the base field or the related one is the author's intent, which no migration can read.
0 commit comments