Skip to content

Commit d5ece3e

Browse files
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
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@objectstack/objectql': minor
3+
---
4+
5+
fix(objectql): an update whose every caller-supplied field is dropped (read-only, or locked by `readonlyWhen`) is a no-op, so the record no longer shows a last-modified edit that changed nothing and `afterUpdate` automation no longer fires for it
6+
7+
Clause-②: no
8+
Metadata-protocol: semantic
9+
10+
An update could send only fields the engine refuses to store: a `readonly` field, or one a TRUE `readonlyWhen` locks for that record. The engine dropped them, reported them in `droppedFields`, and then still wrote the row: `updated_at` and `updated_by` were stamped, and every `afterUpdate` hook ran, so "on update" flows and triggers treated it as a real edit.
11+
12+
Now such an update writes nothing, on a single-record update and on a `multi: true` predicate update alike:
13+
14+
- no driver write, so `updated_at` / `updated_by` keep their stored values;
15+
- `afterUpdate` does not run, no roll-up recomputes and no record-changed event is published;
16+
- a single-record update answers the current record, and a predicate update answers `0` rows written;
17+
- the dropped fields are still reported exactly as before (`onFieldsDropped`, and the REST `droppedFields` answer).
18+
19+
`beforeUpdate` still runs, as it must before the engine can know what is left. When at least one field survives (a caller field, or a field a `beforeUpdate` hook wrote), the update takes the unchanged path. An update whose fields are all kept but equal to the stored values is unchanged. `strictReadonlyWrites` still refuses a dropped field before anything is written.
20+
21+
What to check in an app: an `afterUpdate` hook or record-change trigger that relied on firing for an update made only of read-only or locked fields no longer runs for it. Send a writable field in that update if the automation must run.

‎packages/objectql/src/engine-blank-typed-value-door.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ describe('engine write doors: a blank on a non-string-typed column reaches the d
242242

243243
it('a readonlyWhen lock still holds against a caller blank — the snapshot it judges is the normalised one', async () => {
244244
await engine.insert('blank_req', { id: 'l1', r_number: 1, status: 'closed', locked_amount: 10 });
245-
await engine.update('blank_req', { id: 'l1', locked_amount: '' });
245+
// `status` (unchanged, writable) survives the strip, so the write reaches
246+
// the driver: an update whose every caller key is dropped writes nothing.
247+
await engine.update('blank_req', { id: 'l1', status: 'closed', locked_amount: '' });
246248
const sent = last('update');
247249
expect('locked_amount' in sent).toBe(false);
248250
expect(stub.rows.get('l1')?.locked_amount).toBe(10);

‎packages/objectql/src/engine-formula-write-strip.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,14 @@ describe('[#20805] update — by id and multi, the same strip and the same repor
244244
it('control: a static readonly key on update is still reported under `readonly`', async () => {
245245
const { engine, calls } = await makeEngine();
246246
const l = listener();
247-
await engine.update('proj', { id: 'rec_1', note: 'forged', doubled: 99 }, { onFieldsDropped: l.onFieldsDropped });
247+
// `title` survives both strips: an update whose every caller key is
248+
// dropped writes nothing (engine-update-all-dropped-noop-34746.test.ts).
249+
await engine.update('proj', { id: 'rec_1', note: 'forged', doubled: 99, title: 'z' }, { onFieldsDropped: l.onFieldsDropped });
248250

249251
const data = calls.find((c) => c.fn === 'update')!.data;
250252
expect(data).not.toHaveProperty('note');
251253
expect(data).not.toHaveProperty('doubled');
254+
expect(data).toMatchObject({ title: 'z' });
252255
expect(l.events).toContainEqual(COMPUTED_DOUBLED);
253256
expect(l.events).toContainEqual({ object: 'proj', fields: ['note'], reason: 'readonly' });
254257
});

0 commit comments

Comments
 (0)