Repository navigation
Commit b91cefa
fix(objectql)!: a multi-row insert counts its earlier rows into the parent summary a field-level parent. predicate reads (#34612)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9CEK3WVYUqxMjpD1xegmPGF)_
Fixes #34466
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — skills/** teaches the parent. predicate
(objectstack-formula SKILL.md, parent.status) but says nothing on how a
multi-row insert reads a parent summary
## 维护者速读
- 改了什么:一次插入多行明细时,明细字段上读父记录汇总的 `requiredWhen`(例如 `parent.line_count >=
2`)现在把同批前面已通过的行算进汇总,和一行一行插入的结果一致;导入的试运行(预览)也一样。
- 为什么改:#25579 已裁「批量等于逐条」,当时只覆盖了通过引用读父记录汇总的校验规则,读 `parent.`
的字段级条件仍按批前的值判断,同一批三条空描述的明细会全部通过,逐条插入时第三条会被拒。
- 风险与回滚:收窄(BREAKING):今天一次批量能写进去的某些行,修后会被拒(只影响用 `parent.汇总字段` 写
`requiredWhen` 的明细对象,hotcrm 与示例应用里没找到)。读非汇总字段的条件(如
`parent.status`)、单行插入、更新都不变。回滚即撤回本 PR,无数据迁移。
- 先看:`packages/objectql/src/summary-batch-accumulation.ts`(新增
`overlayRow`)、`packages/objectql/src/engine-insert.ts`(`insertParentOf`)、`packages/objectql/src/summary-rollup.test.ts`(末尾
#34466 一组)。
- 两分钟验证:`pnpm --filter @objectstack/objectql exec vitest run
--maxWorkers=2 src/summary-rollup.test.ts`,预期全过;其中 #34466 一组 7 条,去掉修复后 3
条变红。
- 需要你做的:无,席位落地(需契约档 L2 审核记录)。
## What changes
A multi-row insert reads the master-detail header once for the whole
batch (`resolveMasterDetailParents`, for a detail object that declares a
`parent`-scoped `requiredWhen`). Since #25579 the rows the rules admit
are accumulated in memory and overlaid on the related binding a
validation rule reads through a reference; the header a field-level
`parent.` predicate reads was not overlaid, so every row judged
`parent.SUMMARY` as it stood before the batch. #25579's dev report named
this as outside its card.
- `packages/objectql/src/summary-batch-accumulation.ts` —
`BatchSummaryAccumulator.overlayRow(object, row)`: the same overlay for
one stored row of the roll-up's parent object (a copy; an unbound
header, `null` or `undefined`, is returned as it is). `overlay()` now
shares its per-row body (`patchRow`); its behaviour does not move.
- `packages/objectql/src/engine-insert.ts` — the validation loop binds
`parent` through `insertParentOf`, which overlays the header when the
batch has an accumulator and the object has one master-detail relation.
- `packages/objectql/src/engine-validate.ts` — the multi-row insert
preview binds `parent` the same way, so the import's dry run answers
what the commit does (#25579 changed the preview and the write
together). Added to the claim's file surface by the area (comment on
#34466).
- `content/docs/data-modeling/fields.mdx` — one sentence in the
bulk-create paragraph: a detail object's `requiredWhen` reading the
summary on `parent` reads it the same way.
- `.changeset/34466-batch-insert-parent-summary-predicate.md` — `patch`
on `@objectstack/objectql`, BREAKING, FROM → TO and the one-line fix,
ADR-0087 `not-required (no-migration-prescription)`.
The "Done when" fork of the card: the predicate analysis does name the
field it reads (`summary-rule-reads.ts`, class (ii), landed with
#34439), so this PR makes the insert equal one-by-one; no docs limit is
written.
## Why
Ruling 6377847361 (letter C, 「批量等于逐条,并发不保证」) and ruling record
6928862195 (B, 「被规则读到的合计不延后」): a rule's answer inside one batch is the
answer one-by-one writes give. With `requiredWhen: 'parent.line_count >=
2'` on `description`, three bare lines inserted one at a time admit two
and refuse the third; inserted in one batch they were all admitted.
What narrows, named in the changeset: such a batch now refuses the row
one-by-one inserts refuse (`insert(array)` refuses the whole batch;
`insertMany` reports that row `ok: false`). Not moved: a `parent.`
predicate reading a field that is no summary (`parent.status`), a
single-row insert, an update, an unbound header, an `avg` summary (it
keeps reading the stored value, as on the reference arm).
## Tests
- `packages/objectql/src/summary-rollup.test.ts` — a new top-level
`describe` (#34466) on the file's memory driver, where the roll-up
recompute runs for real: the one-by-one reference answer;
`insert(array)` refuses with `VALIDATION_FAILED` / 400 / `description:
required` and writes nothing; `insertMany` lands the first two and
reports the third; a refused row is not counted; two headers in one
batch count separately; CONTROL `parent.status` answers as before (draft
admits, sent refuses on `note`); the multi-row preview answers `[true,
true, false]`.
- `packages/objectql/src/summary-batch-accumulation.test.ts` —
`overlayRow` moves the summary on a copy; leaves an unbound header,
another parent id, another object and a header not handed the summary as
they were.
Ablation (`node scripts/ablation-replace.mjs`, one mutation):
`overlayRow`'s `return (patchRow(object, row) as R | undefined) ?? row;`
replaced with `return row;` (anchor x1 → x0, blob `6d5e97b4ab77` →
`e61da8f1f2ce`). These suites import the engine from source, so no
rebuild. Result: `Tests 4 failed | 82 passed (86)` — red:
`insert(array)`, `insertMany`, the preview, and the `overlayRow` unit
pin; green as predicted: one-by-one, refused-row, two-headers, CONTROL
and the "leaves as it was" unit pin. Restore: blob `6d5e97b4ab77` ==
HEAD, `git diff HEAD` empty.
## Acceptance notes
- PR #34503 (#34412, same area, still open) edits call-site comments in
`engine-insert.ts`: `git merge-tree --write-tree` of this head against
its head `ea224164` is clean.
- Hooks and flow steps still read the pre-batch header inside one batch,
as ruling record 6928862195 states for both doors.
- The sibling #34465 (a predicate update, `multi: true`) is not touched
here; it follows in its own PR.
## Verification
Readings below were taken at `978472fc` (the fix commit, before
`origin/main` was merged at `3b8da3ef`). The merge brings no change to
`packages/objectql`; the full dogfood battery and the derived gate round
are re-run on the final head and reported in the `os-dev-report` comment
on #34466.
<details><summary>Full dogfood battery (978472f)</summary>
- Closure build: `pnpm --workspace-concurrency=2 --filter
'@objectstack/dogfood^...' build` under `os-verify-lock.sh`: `VERDICT
command-exit 0`.
- `bash scripts/pm/os-verify-lock.sh -c "pnpm --filter
@objectstack/dogfood test"` (no shard, no path): `Test Files 478 passed
| 3 skipped (481)`, `Tests 4054 passed | 68 skipped (4122)`, `VERDICT
command-exit 0`. No failure.
</details>
<details><summary>Local runs (978472f)</summary>
- `pnpm --filter @objectstack/objectql test`: `Test Files 605 passed
(605)`, `Tests 13569 passed (13569)`.
- `pnpm --filter @objectstack/objectql run typecheck`: exit 0
(`check:test-typecheck` OK, ledger held).
- Pin files: `summary-rollup.test.ts` +
`summary-batch-accumulation.test.ts`: `Tests 86 passed (86)`.
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`: 97 families, each run with its exit
recorded; four first exited 3 (prerequisite not met: the teardown
fixture commit, `check:skill-examples`, `check:dual-build-cjs-loads`,
and `check:type-check-debt` queued behind the battery) and were re-run
after `git fetch` of the fixture and a full `pnpm build --concurrency=2`
(119/119 tasks): all exit 0. `--ran`: `97 derived famil(ies) accounted
for — 97 run, 0 NOT-MEASURED`.
- `pnpm lint` and the rest of the farm: CI.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(`packages/spec` not touched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` is CI's run (not run locally).
- [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: its generated artifacts are
regenerated and committed. (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.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmPgdzD1Rp6LuxSPNpk)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmPgdzD1Rp6LuxSPNpk
<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmSLi1reMd27fT62jJ3 -->
Co-authored-by: Claude <noreply@anthropic.com>1 parent 62d9d0d commit b91cefa
7 files changed
Lines changed: 227 additions & 17 deletions
File tree
- .changeset
- content/docs/data-modeling
- packages/objectql/src
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
428 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
429 | 433 | | |
430 | 434 | | |
431 | 435 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| |||
1316 | 1317 | | |
1317 | 1318 | | |
1318 | 1319 | | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
1319 | 1330 | | |
1320 | 1331 | | |
1321 | 1332 | | |
| |||
1349 | 1360 | | |
1350 | 1361 | | |
1351 | 1362 | | |
1352 | | - | |
| 1363 | + | |
1353 | 1364 | | |
1354 | 1365 | | |
1355 | 1366 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
513 | 514 | | |
514 | 515 | | |
515 | 516 | | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
516 | 522 | | |
517 | 523 | | |
518 | 524 | | |
| |||
628 | 634 | | |
629 | 635 | | |
630 | 636 | | |
631 | | - | |
| 637 | + | |
632 | 638 | | |
633 | 639 | | |
634 | 640 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
| |||
69 | 74 | | |
70 | 75 | | |
71 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
72 | 86 | | |
73 | 87 | | |
74 | 88 | | |
| |||
167 | 181 | | |
168 | 182 | | |
169 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
170 | 202 | | |
171 | 203 | | |
172 | 204 | | |
173 | 205 | | |
174 | 206 | | |
175 | 207 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
| 208 | + | |
189 | 209 | | |
190 | 210 | | |
191 | 211 | | |
| |||
194 | 214 | | |
195 | 215 | | |
196 | 216 | | |
197 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
198 | 223 | | |
0 commit comments