Repository navigation
Commit d5ece3e
fix(objectql): an update whose every caller-supplied field is dropped is a no-op (#35594)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6Jao6bxiPKCvVuzoFTExumbxoz)_
Fixes #34746
Clause-②: no
Metadata-protocol: semantic
Skills-docs: follow-up #35605
## 维护者速读
-
用户能看到什么变化:用户、导入或自动化提交的一次更新里,如果所有字段都是只读字段或被条件锁住的字段,系统不再改这条记录,记录头的「最后修改人/时间」保持原样,返回原记录,并照常提示哪些字段被丢弃;单条更新和批量更新都一样。
- 为什么做:什么都没改的更新以前会被记成「刚被某人修改」,还会白白触发「更新后」的流程和触发器,影响审批和审计记录的可信度。
-
出错会怎样:只有「所有字段都被丢弃」的更新受影响,依赖这种更新去触发「更新后」自动化的应用会不再触发;只要还有一个字段真的写入,行为与以前完全一样;可以直接撤回本次改动恢复旧行为。
- 要你做什么:无。
## What changes
`packages/objectql/src/engine-update.ts`, both dispatch branches. After
the two read-only strips, the engine asks one question
(`everyCallerKeyDropped`): did the strips take every key the caller
supplied? When yes, the update is a no-op:
- no `driver.update` / `driver.updateMany` call, so no `updated_at` /
`updated_by` stamp lands;
- `afterUpdate` does not run; no roll-up recompute, no realtime change
event;
- by-id answers the current record: the prior row the not-found gate
already read, so no second fetch; predicate answers `0`, the written-row
count that branch already returns;
- every drop is reported as before (`onFieldsDropped`, so the REST
`droppedFields` answer is unchanged).
The rule as implemented. All three must hold:
1. the caller supplied at least one key, the row's own address `id`
aside. An empty payload is unchanged;
2. every one of those keys was taken by an engine strip on this call:
read-only, `readonlyWhen`, computed, or primary key. Drops are now
recorded whether or not a listener is registered. Emission is unchanged;
3. the payload the strips leave holds only the platform update stamps
(`updated_at`, `updated_by`, which the builtin `sys_stamp_audit_update`
hook writes) plus, by-id, the address. **A key a `beforeUpdate` hook
wrote survives, so that update is not all-dropped** and takes the
unchanged path.
`beforeUpdate` runs before the strip, as it must: the strip can only
judge the post-hook payload. Strict mode is unchanged, because
`assertNoStrictDrops()` still refuses before the driver call. An engine
write precondition (ADR-0142 D4, the assignment claim) keeps its
conditional write and its conflict answer: the verdict is `false` when
one is present. Validation, the post-image seam and the reference checks
still run on the no-op path exactly as they did. Only the statement and
what follows it change, so a refusal that answered before still answers.
## Tests
- New
`packages/objectql/src/engine-update-all-dropped-noop-34746.test.ts` (10
cases). It boots through the real `ObjectQLPlugin`, so the stamps come
from the builtin hook. It uses a capturing driver. By-id and predicate
each cover readonly-only, readonlyWhen-only, a surviving caller field
(control), and a hook-written key (control). By-id adds both reasons
together and strict mode.
- Premise reading on base `b65488a8` (before the engine change): 7 of 10
red. The by-id driver received `{id, updated_at, updated_by}` and the
predicate driver `{updated_at, updated_by}`, with afterUpdate run each
time. The 2 control reds were only the address `id` the by-id driver
payload carries, which I corrected in the expectation.
- Ablation (guard forced false, on disk through
`scripts/ablation-replace.mjs`, restored to HEAD blob `215cfc4e`): 5
defect cases red, 5 controls green.
- Tests the change legitimately reds. Their payload was otherwise all
dropped, and each now carries one surviving writable field, so it still
pins the strip it was written for:
- `engine.test.ts` › Dropped-field write observability: readonlyWhen
single-id, bulk path, throwing listener;
- `engine-formula-write-strip.test.ts` › control: static readonly key on
update;
- `engine-blank-typed-value-door.test.ts` › readonlyWhen lock against a
caller blank;
- `federated-injected-column-readers.test.ts` gains two `not-a-read`
rows for the new stamp-key vocabulary.
<details><summary>Local runs</summary>
- `pnpm --filter @objectstack/objectql test` on the merged head
`2cdd016db`: Test Files 617 passed (617), Tests 13917 passed (13917).
`pnpm --filter @objectstack/objectql typecheck`: exit 0 (lock VERDICT
command-exit 0).
- Ablation: `Tests 5 failed | 5 passed (10)`, then `ok restored: blob ==
HEAD (215cfc4) and git diff HEAD is empty`.
- Final head `44b4972c7` (one test-only commit after the full run,
giving the new file's `find` double the caller's bound): new file 10
passed (10); `check:objectql-double-limit`, `check:test-source-alias`,
`check:cross-package-test-inputs`, `check:nul-bytes`,
`check:engine-double-contract` exit 0.
- Derived gates (`dispatch-gates.mjs --commands`, 65 families): 63 exit
0; NOT MEASURED, exit 3 prerequisite: `check-plugin-teardown-shape
--self-test` (shallow clone cannot reach its pinned fixture commit) and
`check:dual-build-cjs-loads` (reads every package's dist; only the
objectql closure is built here). `--ran` reconciliation: 65 derived, 63
run, 2 NOT-MEASURED, 0 UNRUN.
</details>
## Acceptance notes
- `__search` (pinyin companion) is a hook-written key. Under this rule
it counts as surviving, so an update whose only source field is
`readonlyWhen`-locked, on an object with a companion column, still
writes `__search` plus stamps. Unchanged behaviour, noted and not filed:
no repro of a wrong answer through a public door yet.
- A caller that sends only `updated_at`: the stamp hook overwrites the
key, so no strip reports it and the update is not all-dropped.
Unchanged.
## Verification
Read first:
1. `packages/objectql/src/engine-update.ts`: `everyCallerKeyDropped` and
`engineDroppedKeys` (near `reportDroppedFields`). The risk is the rule's
third clause.
2. `packages/objectql/src/engine-update.ts`: the two `noOpUpdate ?`
sites at the driver calls, and the skipped `afterUpdate` / roll-up /
publish.
3. The new test file's two hook-written controls.
Two-minute check: `pnpm --filter @objectstack/objectql exec vitest run
src/engine-update-all-dropped-noop-34746.test.ts` should print 10
passed.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7
<!-- signed: repo:objectstack#7 · os-tesla ·
session_01L9qibwJEh7hMPPvagWM1g7 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent f7b172f commit d5ece3e
7 files changed
Lines changed: 510 additions & 14 deletions
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
245 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
246 | 248 | | |
247 | 249 | | |
248 | 250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
248 | 250 | | |
249 | 251 | | |
250 | 252 | | |
251 | 253 | | |
| 254 | + | |
252 | 255 | | |
253 | 256 | | |
254 | 257 | | |
| |||
0 commit comments