Skip to content

Commit 344a16d

Browse 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>
1 parent f2bf293 commit 344a16d

7 files changed

Lines changed: 210 additions & 20 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/objectql': patch
3+
---
4+
5+
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.

‎content/docs/api/error-catalog.mdx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,15 @@ object is rejected with `400 VALIDATION_FAILED`, and the specifics ride in
316316
}
317317
```
318318

319-
The check covers create, update and bulk update. Three cases are deliberately
319+
The check covers create, update and bulk update. Four cases are deliberately
320320
*not* rejections: an empty value (`null` / `""` / `[]`) means "no link", a
321321
`isSystem` write is exempt (seed replay and package install legitimately write
322-
in an order that only resolves once the batch completes), and a target that
322+
in an order that only resolves once the batch completes), a target that
323323
cannot be checked at all — an unregistered object, an unreachable datasource —
324-
fails **open** rather than inventing a rejection.
324+
fails **open** rather than inventing a rejection, and an update that carries back
325+
a value (or a member of a multi-valued field) the row already stores is not
326+
judged again, because the update does not add it; on a bulk update that holds
327+
only when every matched row already stores it.
325328
</Callout>
326329

327330
### `DUPLICATE_VALUE`

‎content/docs/data-modeling/fields.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ The key's full contract is in the [Field reference](/docs/references/data/field)
284284
`lookup` / `master_detail` to an id with no matching row in the target object is
285285
rejected with `400 VALIDATION_FAILED` and a `fields[]` entry whose `code` is
286286
`reference_not_found` (see the [error catalog](/docs/api/error-catalog)). The
287-
same check runs on bulk updates.
287+
same check runs on bulk updates. An update judges only the references it adds: a
288+
value the row already stores, carried back unchanged, is not judged again, so a
289+
deleted user's id left in a `user` field does not block later edits of the record.
288290
289291
Clearing a relationship is not a dangling reference: `null`, `""` and `[]` all mean
290292
"no link". Which of them `deleteBehavior: 'set_null'` writes when the referenced

‎packages/objectql/src/engine-lookup-referential-integrity.test.ts‎

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,130 @@ describe('[#4441] a lookup id that resolves to nothing is refused', () => {
402402
expect(row.other).toBe('whatever');
403403
});
404404
});
405+
406+
/**
407+
* [#29062] The write judges only the reference values it ADDS.
408+
*
409+
* The delete walk leaves a `user` / `multi_user` value naming a deleted user
410+
* in place (`DELETE_SEMANTICS_REFERENCE_TYPES` in `engine.ts` leaves `user` out
411+
* by declaration), so a row can hold an id that names no user. An edit form
412+
* PATCHes the whole record back, that id included, and the check used to judge
413+
* every value the payload carried: the editor was refused `reference_not_found`
414+
* for a value they never touched. A value, or a multi-valued member, already
415+
* stored on the row is not this write's reference and is not judged again; a
416+
* newly added missing id is refused exactly as before.
417+
*/
418+
describe('[#29062] a reference value already stored on the row is not judged again', () => {
419+
let engine: ObjectQL;
420+
let stores: Map<string, Map<string, Record<string, unknown>>>;
421+
const userCtx = { userId: 'u_alive' };
422+
const sys = { context: { isSystem: true } } as any;
423+
424+
const sysUser = {
425+
name: 'sys_user',
426+
label: 'User',
427+
fields: {
428+
id: { name: 'id', label: 'ID', type: 'text' as const, primaryKey: true },
429+
name: { name: 'name', label: 'Name', type: 'text' as const },
430+
},
431+
};
432+
const holder = {
433+
name: 'ref_holder',
434+
label: 'Holder',
435+
fields: {
436+
id: { name: 'id', label: 'ID', type: 'text' as const, primaryKey: true },
437+
title: { name: 'title', label: 'Title', type: 'text' as const },
438+
owner_user: { name: 'owner_user', label: 'Owner', type: 'user' as const },
439+
members: { name: 'members', label: 'Members', type: 'user' as const, multiple: true },
440+
project: { name: 'project', label: 'Project', type: 'lookup' as const, reference: 'ref_permission_set' },
441+
tags: { name: 'tags', label: 'Tags', type: 'lookup' as const, reference: 'ref_permission_set', multiple: true },
442+
},
443+
};
444+
445+
beforeEach(async () => {
446+
engine = new ObjectQL();
447+
const stub = makeStubDriver();
448+
stores = stub.stores;
449+
engine.registerDriver(stub.driver, true);
450+
await engine.init();
451+
engine.registry.registerObject(sysUser as any);
452+
engine.registry.registerObject(permissionSet);
453+
engine.registry.registerObject(holder as any);
454+
for (const id of ['u_alive', 'u_gone']) await engine.insert('sys_user', { id, name: id }, sys);
455+
await engine.insert('ref_permission_set', { id: 'ps_real', name: 'Real' }, sys);
456+
await engine.insert(
457+
'ref_holder',
458+
{ id: 'h1', title: 'T', owner_user: 'u_gone', members: ['u_alive', 'u_gone'] },
459+
{ context: userCtx } as any,
460+
);
461+
// The user is deleted afterwards; the walk leaves both stored values in place.
462+
await engine.delete('sys_user', { where: { id: 'u_gone' }, context: { isSystem: true } } as any);
463+
expect(stores.get('sys_user')?.has('u_gone')).toBe(false);
464+
expect(stores.get('ref_holder')?.get('h1')).toMatchObject({ owner_user: 'u_gone', members: ['u_alive', 'u_gone'] });
465+
});
466+
467+
const patch = (data: Record<string, unknown>) =>
468+
engine.update('ref_holder', data, { where: { id: 'h1' }, context: userCtx } as any);
469+
470+
it('a single user field carried back unchanged is not refused', async () => {
471+
const row: any = await patch({ title: 'T2', owner_user: 'u_gone' });
472+
expect(row.title).toBe('T2');
473+
expect(stores.get('ref_holder')?.get('h1')?.owner_user).toBe('u_gone');
474+
});
475+
476+
it('a multi user field carried back unchanged is not refused', async () => {
477+
const row: any = await patch({ title: 'T2', members: ['u_alive', 'u_gone'] });
478+
expect(row.title).toBe('T2');
479+
expect(stores.get('ref_holder')?.get('h1')?.members).toEqual(['u_alive', 'u_gone']);
480+
});
481+
482+
it('a multi user field keeping its stored ghost and adding a new one refuses only the new one', async () => {
483+
const err = await refusalOf(() => patch({ members: ['u_alive', 'u_gone', 'u_never'] }));
484+
expect(err.code).toBe('VALIDATION_FAILED');
485+
expect(err.fields).toHaveLength(1);
486+
expect(err.fields[0]).toMatchObject({ field: 'members', code: 'reference_not_found', value: 'u_never' });
487+
expect(stores.get('ref_holder')?.get('h1')?.members).toEqual(['u_alive', 'u_gone']);
488+
});
489+
490+
it('a single user field repointed at another missing user is still refused', async () => {
491+
const err = await refusalOf(() => patch({ owner_user: 'u_never' }));
492+
expect(err.fields).toHaveLength(1);
493+
expect(err.fields[0]).toMatchObject({ field: 'owner_user', code: 'reference_not_found', value: 'u_never' });
494+
});
495+
496+
it('an insert naming the deleted user is still refused', async () => {
497+
const err = await refusalOf(() =>
498+
engine.insert('ref_holder', { title: 'N', members: ['u_alive', 'u_gone'] }, { context: userCtx } as any),
499+
);
500+
expect(err.fields).toHaveLength(1);
501+
expect(err.fields[0]).toMatchObject({ field: 'members', code: 'reference_not_found', value: 'u_gone' });
502+
});
503+
504+
it('a lookup that adds a missing id is still refused, member by member', async () => {
505+
await patch({ project: 'ps_real', tags: ['ps_real'] });
506+
const single = await refusalOf(() => patch({ project: 'ps_missing' }));
507+
expect(single.fields[0]).toMatchObject({ field: 'project', code: 'reference_not_found', value: 'ps_missing' });
508+
const multi = await refusalOf(() => patch({ tags: ['ps_real', 'ps_missing'] }));
509+
expect(multi.fields).toHaveLength(1);
510+
expect(multi.fields[0]).toMatchObject({ field: 'tags', code: 'reference_not_found', value: 'ps_missing' });
511+
});
512+
513+
it('a bulk update forgives a value only when every matched row already holds it', async () => {
514+
await engine.insert('ref_holder', { id: 'h2', title: 'T', members: ['u_alive'] }, { context: userCtx } as any);
515+
// h1 holds u_gone, so a bulk write over h1 alone carries it back untouched.
516+
await engine.update(
517+
'ref_holder', { members: ['u_alive', 'u_gone'] },
518+
{ where: { id: 'h1' }, multi: true, context: userCtx } as any,
519+
);
520+
// Over h1 and h2 the same payload ADDS u_gone to h2: refused, nothing written.
521+
const err = await refusalOf(() =>
522+
engine.update(
523+
'ref_holder', { members: ['u_alive', 'u_gone'] },
524+
{ where: { title: 'T' }, multi: true, context: userCtx } as any,
525+
),
526+
);
527+
expect(err.fields).toHaveLength(1);
528+
expect(err.fields[0]).toMatchObject({ field: 'members', code: 'reference_not_found', value: 'u_gone' });
529+
expect(stores.get('ref_holder')?.get('h2')?.members).toEqual(['u_alive']);
530+
});
531+
});

‎packages/objectql/src/engine-referential-integrity.ts‎

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export async function assertReferencesResolve(
8787
supplied: Record<string, unknown> | null | undefined,
8888
context: any,
8989
msgCtx?: { locale?: string; translate?: any; objectName?: string },
90+
storedRows?: StoredReferenceRows,
9091
): Promise<void> {
9192
// [#28881] A system caller is exempt, except a flow run's elevated write:
9293
// its elevation is for authorization, and it keeps this check (see
@@ -95,7 +96,7 @@ export async function assertReferencesResolve(
9596
const fields = schema?.fields;
9697
if (!fields || !data) return;
9798

98-
const failures: any[] = [];
99+
const refused: Array<{ name: string; def: any; value: unknown; target: string }> = [];
99100
for (const name of Object.keys(fields)) {
100101
// [#4441, narrowing kept by #4743] A `readonly` field is never the
101102
// caller's to answer for — BY CONSTRUCTION, not by exemption.
@@ -155,23 +156,49 @@ export async function assertReferencesResolve(
155156
const resolved = def?.type === 'master_detail'
156157
? await this.masterDetailHeaderExists(target, v, context)
157158
: await this.referenceExists(target, v, context);
158-
if (resolved === false) {
159-
failures.push(buildFieldError(
160-
{
161-
field: name,
162-
code: 'reference_not_found',
163-
def,
164-
value: String(v),
165-
constraint: { target },
166-
},
167-
msgCtx as any,
168-
));
169-
}
159+
if (resolved === false) refused.push({ name, def, value: v, target });
170160
}
171161
}
162+
if (refused.length === 0) return;
163+
// [#29062] A refused value every row this write lands on already stores
164+
// is not a reference the write ADDS, so it is not this caller's to answer
165+
// for. The stored rows are read only now, once a probe has refused.
166+
const stored = storedRows ? (await storedRows() ?? []).filter(isRow) : [];
167+
const failures = refused
168+
.filter((r) => stored.length === 0 || !stored.every((row) => storedReferenceIds(row[r.name]).has(String(r.value))))
169+
.map((r) => buildFieldError(
170+
{
171+
field: r.name,
172+
code: 'reference_not_found',
173+
def: r.def,
174+
value: String(r.value),
175+
constraint: { target: r.target },
176+
},
177+
msgCtx as any,
178+
));
172179
if (failures.length > 0) throw new ValidationError(failures);
173180
}
174181

182+
/**
183+
* [#29062] The rows a write lands on, as stored before it, read on demand by
184+
* {@link assertReferencesResolve}: the by-id update's prior row, or the
185+
* matched rows of a predicate update. Absent (an insert), every value the
186+
* caller supplied is the write's own.
187+
*/
188+
export type StoredReferenceRows = () => Promise<ReadonlyArray<Record<string, unknown> | null | undefined> | null>;
189+
190+
function isRow(row: unknown): row is Record<string, unknown> {
191+
return row !== null && typeof row === 'object';
192+
}
193+
194+
/** The ids a stored reference value holds: each member of a multi-valued one, or the one scalar. */
195+
function storedReferenceIds(value: unknown): ReadonlySet<string> {
196+
const members = Array.isArray(value) ? value : [value];
197+
const ids = new Set<string>();
198+
for (const m of members) if (typeof m === 'string' || typeof m === 'number') ids.add(String(m));
199+
return ids;
200+
}
201+
175202
/** The body of `ObjectQL#masterDetailHeadersCallerReads`; the method's docblock there is its contract. */
176203
export async function masterDetailHeadersCallerReads(
177204
this: Pick<ReferentialIntegrityHost, 'find' | 'logger'>,

‎packages/objectql/src/engine-unreadable-master-detail-header.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ describe('[#22519] an unreadable master-detail header answers what a nonexistent
315315
const nowhere = envelopeOf(await refusalOf(() => write(door, NOWHERE, CAROL)));
316316
expect(nowhere).toEqual(NOT_FOUND);
317317
// Alice's own header: it exists, and Carol's read door refuses the object.
318-
expect(envelopeOf(await refusalOf(() => write(door, 'h_mine_open', CAROL)))).toEqual(nowhere);
318+
// [#29062] Not the header line l1 already stores: an update carrying a
319+
// stored value back is not judged again, so a repoint must name another.
320+
expect(envelopeOf(await refusalOf(() => write(door, 'h_mine_locked', CAROL)))).toEqual(nowhere);
319321
});
320322

321323
it('the partial batch insert: an unreadable row fails as a nonexistent row does, and a readable row lands', async () => {

‎packages/objectql/src/engine.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ import { buildEvalUser, buildProvenance, buildSession, buildUser } from './engin
144144
// [#25522 cut 10] The write path's reference check and the caller's read of a
145145
// master-detail header; the methods of the same names below hand each body the
146146
// members it reads (`ReferentialIntegrityHost`).
147-
import { assertReferencesResolve, masterDetailHeadersCallerReads } from './engine-referential-integrity.js';
147+
import { assertReferencesResolve, masterDetailHeadersCallerReads, type StoredReferenceRows } from './engine-referential-integrity.js';
148148
// [#25522 cut 11] File-field hydration on read; the methods of the same names
149149
// below hand each body the members it reads (`FileReferenceHydrationHost`).
150150
import { callerMayReadSysFile, readParentDerivedFiles, resolveFileReferences, servableFileRows, serveRefusedFileHydration } from './engine-file-reference-hydration.js';
@@ -10416,6 +10416,15 @@ export class ObjectQL implements IObjectQLEngine {
1041610416
* "no link", which is what `deleteBehavior: 'set_null'` produces.
1041710417
* - **Already-expanded objects are skipped.** A read round-trip can hand back
1041810418
* `{id, name, …}` in the slot; that is not an id write.
10419+
* - **A value the row already stores is not the write's (#29062).** The
10420+
* check judges only the references a write ADDS. An update's `storedRows`
10421+
* (the by-id prior row; a predicate update's matched rows) forgive a
10422+
* refused value, or a multi-valued member, that every one of those rows
10423+
* already holds: an edit form carries the whole record back, and a stored
10424+
* id that has since stopped resolving (the delete walk leaves a `user`
10425+
* value in place, `DELETE_SEMANTICS_REFERENCE_TYPES`) is not the editor's
10426+
* to answer for. A value new to any of the rows is refused as before, and
10427+
* an insert has no stored rows, so every value it supplies is judged.
1041910428
*
1042010429
* ## Why the probe bypasses RLS — and why it keeps the tenant wall
1042110430
*
@@ -10470,13 +10479,14 @@ export class ObjectQL implements IObjectQLEngine {
1047010479
supplied: Record<string, unknown> | null | undefined,
1047110480
context: any,
1047210481
msgCtx?: { locale?: string; translate?: any; objectName?: string },
10482+
storedRows?: StoredReferenceRows,
1047310483
): Promise<void> {
1047410484
// [#25522 cut 10] The body moved to `engine-referential-integrity.ts` (see `ReferentialIntegrityHost`).
1047510485
const host: ThisParameterType<typeof assertReferencesResolve> = {
1047610486
masterDetailHeaderExists: (...a) => this.masterDetailHeaderExists(...a),
1047710487
referenceExists: (...a) => this.referenceExists(...a),
1047810488
};
10479-
return assertReferencesResolve.call(host, schema, data, supplied, context, msgCtx);
10489+
return assertReferencesResolve.call(host, schema, data, supplied, context, msgCtx, storedRows);
1048010490
}
1048110491

1048210492
/**
@@ -18160,9 +18170,12 @@ export class ObjectQL implements IObjectQLEngine {
1816018170
const permissionsForUpdate = (await this.resolveOptionPermissions(updateSchema, [updatePayload], permissionResolution))(updatePayload);
1816118171
emitValidationAdvisories(options?.onValidationAdvisory, evaluateValidationRules(updateSchema as any, hookContext.input.data as Record<string, unknown>, 'update', { previous: priorRecord, logger: this.logger, currentUser: this.buildEvalUser(opCtx.context), skipStateMachine: shouldSkipStateMachine(opCtx.context), messages: updateMsgCtx, parent: roWhenParent, previousParent: roWhenPreviousParent, related: relatedForUpdate, permissions: permissionsForUpdate }), this.logger, object);
1816218172
// [#4441] A repoint is as capable of dangling as an initial link.
18173+
// [#29062] …but a value the row already stores is not a repoint:
18174+
// the prior row is what the check forgives a refused value against.
1816318175
await this.assertReferencesResolve(
1816418176
updateSchema, hookContext.input.data as Record<string, unknown>,
1816518177
opCtx.data as Record<string, unknown>, opCtx.context, updateMsgCtx,
18178+
async () => [priorRecord],
1816618179
);
1816718180
// [commit 9d7f7259f] The by-id driver exit — where a driver's refusal
1816818181
// leaves this door, and where a recognised unique violation
@@ -18586,9 +18599,13 @@ export class ObjectQL implements IObjectQLEngine {
1858618599
// [#4441] The bulk call site too — a guard wired into single-id
1858718600
// writes only is still a hole one call site over (AGENTS.md
1858818601
// PD #10's own worked example, #3106).
18602+
// [#29062] A refused value is forgiven only when EVERY matched row
18603+
// already stores it (the `readPriorRows` memo, read only then);
18604+
// a row it is new to makes it this write's reference.
1858918605
await this.assertReferencesResolve(
1859018606
updateSchema, hookContext.input.data as Record<string, unknown>,
1859118607
opCtx.data as Record<string, unknown>, opCtx.context, updateMsgCtx,
18608+
readPriorRows,
1859218609
);
1859318610
// `updateMany` presence is part of the ladder verdict resolved above.
1859418611
// [commit 9d7f7259f] The predicate driver exit, enveloped on the same

0 commit comments

Comments
 (0)