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 344a16d
Browse filesBrowse the repository at this point in the historyBrowse files
fix(objectql): an update carrying a stored reference back unchanged is not refused because it stopped resolving (#29062) (#29245)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi93jDJpyZ4T5x8DmbvSnfEjZ)_Fixes#29062
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 改了什么:写入时的引用校验只判这次写入"新增"的引用值;记录里本来就存着、这次原样带回的值(包括多用户字段里的单个成员)不再重判。
- 为什么改:删除用户后,单/多用户字段里仍留着该用户 id(删除联动不覆盖 user 类型);之后编辑这条记录、表单把整条记录带回时,会被
reference_not_found 拒绝,而编辑者根本没碰这个字段。
- 风险与回滚:只放宽不收紧,以前能过的写入现在照样能过;新增的不存在 id 仍然拒绝,插入仍逐值校验。回滚即 revert 本 PR。
-
先看:packages/objectql/src/engine-referential-integrity.ts(被拒值与存量行比对的那段),packages/objectql/src/engine.ts(按
id
更新与批量更新两处调用),packages/objectql/src/engine-lookup-referential-integrity.test.ts(新
describe)。
- 两分钟验证:pnpm --filter @objectstack/objectql exec vitest run
src/engine-lookup-referential-integrity.test.ts,预期 21 条全绿,其中 #29062 的 7
条。
- 需要你做的:无,席位落地。
## What changes
`assertReferencesResolve` (the write-time `reference_not_found` check)
gains an optional `storedRows` reader: the rows the write lands on, as
stored before it. After the probes run, a refused value (or a refused
member of a multi-valued field) that **every** one of those rows already
stores is dropped from the failures: it is not a reference this write
adds. The stored rows are read only once a probe has refused, so a write
whose references all resolve reads nothing new.
Every call site of `this.assertReferencesResolve(` and what it now does:
| Call site | Stored row to compare against | Behaviour |
|---|---|---|
| insert (`engine.ts`, the per-row admit loop) | none | unchanged: every
supplied value is judged |
| update by id (`engine.ts`, after the validation rules) |
`priorRecord`, always read there (the not-found gate) | a refused value
the row already stores is forgiven |
| predicate update, `multi: true` (`engine.ts`, the bulk call site) |
the `readPriorRows` memo (the matched rows), read only after a refusal |
forgiven only when every matched row stores it; zero matched rows
forgive nothing |
| dry run (`engine-validate.ts`) | n/a | runs the check in `insert` mode
only, so unchanged |
| upsert | n/a | the engine has no upsert door (`update.options.upsert`
is retired), so there is no fourth site |
The delete walk is untouched: `DELETE_SEMANTICS_REFERENCE_TYPES` still
leaves `user` out by declaration (moving it is a spec change).
Route B covers the single `user` field as well as the multi-valued one.
The previous measurement on this card (os-dev-report 6571331581) showed
the single field refused the same way: a PATCH carrying `f_user`
unchanged after the user was removed answered 400 `reference_not_found`.
The rule is not special-cased by type, so it applies to `lookup` and
`master_detail` the same way: a stored value carried back unchanged
answers what omitting it answers.
## Tests
New `describe('[#29062] …')` in
`packages/objectql/src/engine-lookup-referential-integrity.test.ts`,
reusing that file's stub driver. The fixture deletes a `sys_user` row
through `engine.delete` after a holder row names it, so the stored ghost
is the one the delete walk really leaves:
- a single `user` field carried back unchanged passes;
- a multi `user` field carried back unchanged passes;
- a multi `user` field keeping its stored ghost and adding a new ghost
refuses only the new one (`fields` length 1, `value: u_never`), and the
stored value does not move;
- a single `user` field repointed at another missing user is still
refused;
- an insert naming the deleted user is still refused;
- a `lookup` (single and multi) that adds a missing id is still refused,
member by member;
- a bulk update forgives a value only when every matched row already
holds it (over h1 alone it passes; over h1 and h2, where it is new to
h2, it is refused and h2 is not written).
**Forced test edit:**
`packages/objectql/src/engine-unreadable-master-detail-header.test.ts`,
the `%s — a refused read of the header object answers as a nonexistent
header id` case. For the `repoint by id` and `bulk repoint` doors it
wrote `h_mine_open`, which is the header line `l1` already stores (its
`beforeEach`), so the write was not a repoint at all and is now forgiven
like an omitted key. The case now names `h_mine_locked`, another
existing header Carol cannot read, so all four doors still pin "an
existing unreadable header answers what a nonexistent one does". Nothing
else in that file moved; 30/30 pass.
## Acceptance notes
- Out of scope, reported on the card and not fixed here: the stock dev
admin gets 403 on admin remove-user; `deleteBehavior` on a `user` field
is declared but not enforced.
- A `master_detail` header the caller cannot read, carried back
unchanged, now passes (it is the value the row stores, and omitting the
key already passed). A repoint to an unreadable header is still refused
as a nonexistent one.
## Verification
<details><summary>Red first on base 2af0ae2</summary>
`vitest run src/engine-lookup-referential-integrity.test.ts` with only
the new tests committed: `Tests 4 failed | 17 passed (21)`. Failing:
single unchanged, multi unchanged, stored ghost plus new ghost
(`expected [...] to have a length of 1 but got 2`), bulk. Cause line:
`ValidationError: Owner: no sys_user record has id "u_gone"`.
</details>
<details><summary>Ablations (scripts/ablation-replace.mjs, restored blob
== HEAD, git diff HEAD empty)</summary>
1. The old "judge every carried value" behaviour put back (`const stored
= [];` in place of the stored-row read): `Tests 4 failed | 17 passed
(21)`, the same four cases.
2. `every` matched row changed to `some` matched row: `Tests 1 failed |
20 passed (21)`, only the bulk case.
</details>
<details><summary>Tests and gates on the final head 49f236e
(origin/main merged twice; the second merge brings #29060)</summary>
- `pnpm --filter @objectstack/objectql test`: `Test Files 527 passed
(527)`, `Tests 10145 passed (10145)`; `pnpm --filter
@objectstack/objectql typecheck`: exit 0 (lock VERDICT command-exit 0).
- #29060's suites against this change: `service-automation`
`runas-system-reference-check.integration.test.ts` +
`builtin/crud-runas.test.ts`: `Test Files 2 passed (2)`, `Tests 44
passed (44)`. The flow-write reference check #29060 added and this
change compose: a flow repointing a field at a deleted user is still
refused; a stored value carried back is forgiven on either caller.
- `node scripts/pm/dispatch-gates.mjs --commands` (no paths): 63
families derived; all 63 run with exit codes recorded; `--ran`: 62 run,
1 NOT MEASURED. The one is `node scripts/check-plugin-teardown-shape.mjs
--self-test`, exit 3 PREREQUISITE NOT MET (its positive control is
pinned to a commit this shallow clone cannot reach); declared to CI's
`Lint & Repo Gates`.
- `pnpm lint`: exit 0.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmSDzgkXapyAsvrXkrV)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(objectql): an update that carries a stored reference back unchanged is no longer refused because that reference has since stopped resolving (#29062)
6
+
7
+
Clause-②: yes (widening)
8
+
Metadata-protocol: none
9
+
10
+
The write-time reference check (`reference_not_found`) now judges only the reference values a write adds. Deleting a user leaves its id in every `user` field and multi-valued `user` field that named it, because the delete walk does not reach the `user` type. The next edit of such a record, for example an edit form saving the whole record back, was refused `reference_not_found` for a value the editor never touched. Now a value, or a member of a multi-valued field, that the row already stores is not judged again. On an update by id the stored row decides. On a predicate (`multi: true`) update a value is forgiven only when every matched row already stores it. A missing id the write adds is refused exactly as before, and an insert judges every value it supplies.
11
+
12
+
The rule covers every reference type the check reads (`lookup`, `master_detail`, `user` and their multi-valued forms), a single `user` field included. Nothing is narrowed: every write accepted before is still accepted.
0 commit comments