Repository navigation
Commit 4159c70
fix(service-analytics)!: the dataset draft preview refuses a dimension whose field the object does not have, as the live strategies do, instead of grouping every row under one null key (#28259)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DLMAJ9kZMBicdMLygftCdLd)_
domain:server#3 · os-elon-musk · session_016WV4cyQNVxpxREGfKkTsqs
Fixes #28201
Clause-②: no (narrowing) — a draft-preview dataset query (`queryDataset`
with `previewDrafts: true` over a pending seed draft) now refuses a
selected dimension that the native and ObjectQL strategies refuse, which
it served as one `null` group before. No export, answer member, status
or error code is added: the refusal is the live faces' existing
`INVALID_FIELD` / 400.
Metadata-protocol: none
## 维护者速读
- 改了什么:数据集草稿预览遇到对象上不存在的维度(如拼错的 `bogus`),过去把所有行归到一个 `null`
组并给出总数;现在与实时两种策略一样按 400 `INVALID_FIELD`
拒,消息逐字相同。同时把预览各道闸门的顺序对齐实时,两处错误同时出现时三面报出同一个错误。
- 为什么改:草稿里的错别字显示一个空白分组加总数,发布后才被拒;这是 #28172(度量那一半,PR #28210 已合入)的维度那一半。
- 风险与回滚:只影响草稿预览;已声明的维度和用对象真实字段名的未声明维度(如 `amount`)照旧分组,实时策略不变。回滚即 revert。
- 先看:`packages/services/service-analytics/src/analytics-service.ts` 里
`answerDataset` 的 `previewService.query`(新增 `assertDimensionFields`
与闸门顺序)。
- 两分钟验证:`pnpm --filter @objectstack/service-analytics exec vitest run
src/__tests__/preview-undeclared-dimension-parity.test.ts`,预期 7 passed。
- 需要你做的:无,席位落地。
## What changes
**The draft preview's gate list (`analytics-service.ts`, `answerDataset`
→ `previewService.query`).**
- It now asks `assertDimensionFields` (#5520), the gate `ensureCube`
asks on the live path, on the cube with the minted measures and with the
compiled cube's declared dimensions as the vocabulary. A dimension whose
field the object does not have (`bogus`) is refused `INVALID_FIELD` /
400 with the same message, `param: 'dimensions'`, `field` and
`dimension` named, `Valid dimensions:` listing the declared ones. An
undeclared dimension naming a real field stays legal, as the gate's own
contract says, so `amount` still groups on every face.
- Its gates now run in the live order, which #28210's contract review
noted as a non-blocking difference: `ensureCube`'s order (measure fields
#4437, dimension fields #5520, aggregate × field-type #21044, record
currency ADR-0144 D6), then `query()`'s (caller-measure column reference
#21156, stored body #21120, internal fields, field-level read #20917).
The order change is required for parity, not only tidiness: with
`region_sum` beside `bogus` the live faces answer the dimension 400
first, and with `amount + 1` beside `region_sum` they answer the
field-type 400 before the column-reference 403. Before this PR the
preview answered the field-type 400 and the 403 respectively. Both cases
are pinned.
`preview-evaluator.ts` is unchanged: an undeclared dimension over a real
field is legal, and the evaluator has no field list to judge it by; the
service gate above does.
**Not in this PR (measured here, carded by the seat):** a
`runtimeFilter` on a field the object does not have is refused
`INVALID_FIELD` / 400 (`param: 'where'`) live and served as `[]` on the
preview (#28257, which also notes the unmeasured #20807 JSON-dimension
door); a dotted dimension `<dataset>.bogus` is refused live with two
different refusals (native `DATASET_INVALID`, ObjectQL `INVALID_FIELD`)
and served on the preview, which needs a ruling first (#28258).
## Why
Measured on `main` `86cf7cef`, real SQLite engine, a dataset declaring
dimension `region` and measures `total` (sum of `amount`), `deals`
(count):
| selection | native | ObjectQL | draft preview (before) | draft preview
(after) |
|:---|:---|:---|:---|:---|
| dims `['bogus']` | `INVALID_FIELD` / 400 | `INVALID_FIELD` / 400 |
`[{bogus: null, total: 180}]` | `INVALID_FIELD` / 400, same message |
| dims `['bogus', 'region']` | `INVALID_FIELD` / 400 | `INVALID_FIELD` /
400 | two groups with `bogus: null` | `INVALID_FIELD` / 400, same
message |
| dims `['amount']` (real field) | three groups | three groups | three
groups | three groups |
| dims `['region']` (declared) | two groups | two groups | two groups |
two groups |
| `region_sum` + dims `['bogus']` | dimension 400 | dimension 400 |
field-type 400 | dimension 400 |
| `['amount + 1', 'region_sum']` | field-type 400 | field-type 400 |
column-reference 403 | field-type 400 |
## Verification
-
`packages/services/service-analytics/src/__tests__/preview-undeclared-dimension-parity.test.ts`
(new, 7 cases, each over native / ObjectQL / preview through
`queryDataset` on real SQLite): `bogus` refused `INVALID_FIELD` / 400
with `param`, `field`, `dimension` and a message identical on all three
faces; `bogus` beside a declared dimension, same; CONTROLS: `region` and
`amount` serve the same groups on all three; three two-mistake cases
answer the same refusal first on all three (`nope` + `bogus` → the
measure; `region_sum` + `bogus` → the dimension; `amount + 1` +
`region_sum` → the field-type door).
- Ablations (source changed, both parity files rerun, 17 cases):
`analytics-service.ts` reset to `main` ⇒ 4 red (both `bogus` cases and
the two order cases that moved); `assertDimensionFields` removed ⇒ 3 red
(both `bogus` cases, `region_sum` + `bogus`); the field-type door moved
ahead of the dimension gate ⇒ 1 red (`region_sum` + `bogus`); the
caller-measure gate moved back ahead of the field-type door ⇒ 1 red
(`amount + 1` + `region_sum`). The #28172 measure pins stay green in
every arm but the reset.
- `pnpm --filter @objectstack/service-analytics exec vitest run` at
head: 199 files, 4795 passed, 282 skipped, 0 failed. `pnpm --filter
@objectstack/service-analytics typecheck` and eslint on the touched
files clean.
- Every `dispatch-gates --commands` family, `pnpm lint` and the dogfood
battery run at this head: the readings are posted on the card with the
os-dev report.
Skills-docs: none. `git grep -n -i -E "previewDrafts|draft (data
)?preview" -- skills content/docs` (references excluded) finds
`content/docs/data-modeling/currency.mdx:146` (still true) and release
notes; nothing in `skills/` or `content/docs/` describes how the preview
answers an undeclared dimension.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (No formatter ran; the
lint reading is posted on the card with the gate battery.)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: not touched.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English (the 维护者速读 block is the
lane's maintainer summary).
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4cyQNVxpxREGfKkTsqs)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4cyQNVxpxREGfKkTsqs
Co-authored-by: Claude <noreply@anthropic.com>1 parent 0027c4a commit 4159c70
3 files changed
Lines changed: 214 additions & 9 deletions
File tree
- .changeset
- packages/services/service-analytics/src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2763 | 2763 | | |
2764 | 2764 | | |
2765 | 2765 | | |
| 2766 | + | |
| 2767 | + | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
2766 | 2773 | | |
2767 | | - | |
2768 | | - | |
2769 | | - | |
2770 | | - | |
2771 | | - | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
2772 | 2778 | | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
2773 | 2785 | | |
2774 | 2786 | | |
2775 | 2787 | | |
| |||
2778 | 2790 | | |
2779 | 2791 | | |
2780 | 2792 | | |
2781 | | - | |
2782 | | - | |
2783 | | - | |
2784 | | - | |
2785 | 2793 | | |
2786 | 2794 | | |
2787 | 2795 | | |
| |||
0 commit comments