Skip to content

Commit 709a087

Browse files
fix(lint,core)!: refuse a lookup dependsOn filter key naming a formula of its target; an import lookup no scoped read answered is never out of scope (#37910)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu1PSnWkmbF453BynqtyjJc5)_ Fixes #37717 Clause-②: yes (narrowing) Metadata-protocol: narrowed Skills-docs: none — no `skills/` page teaches a `dependsOn` filter key on a formula field; `content/docs/data-modeling/import-mappings.mdx` names the refusal in this change ## 维护者速读 - 应用作者在查找字段的 `dependsOn` 里,把筛选键指向目标对象上的公式字段时,`os validate`、构建以及 Studio、REST、MCP 保存都会直接报错,并点出是哪个字段、为什么不行、该改成哪个存储字段。以前这种写法能发布,之后记录选择器查不出候选,导入这一列的每一行都失败。 - 这是座位复审 PR #37706 时留下的两条小尾巴(导入“值属于另一个父记录”这条提示的后续):一条是作者时提前报错,一条是导入时如果限定范围的查询一次都没得到回答,就不再说“这个值在别的父记录下”,只说找不到记录。 - 出错会怎样:只有用到这种写法的对象下次保存时会被拒;仓库里的示例应用和打包对象、hotcrm 都没有这种写法;存量数据不改写,开机不拒。整张 PR 可以直接撤回。 - 要你做的:这是收严(narrowing),走 Tier H,等你审批。 ## What changes - **`@objectstack/lint`, N2: the `dependsOn` filter key must be filterable.** `validateObjectFieldRefs` (`validate-object-field-refs.ts`) gains a `filtered` flag on its field-name slots, set on the REFERENCE half of `dependsOn` (`param`, else the bare name or `field`), the key the record picker's candidate query and the importer's scoped lookup filter the referenced object by. When that name resolves to an authored field of the referenced object that is computed on read (`isVirtualSearchField` from `@objectstack/spec/data`, the predicate the engine's filter seam and the import resolver already use), it reports at `error`, under the existing rule id `object-field-ref-unknown`, at the entry's path. It runs wherever that rule runs: `os validate` / `lint` / `compile` / `build` and the runtime publish gate for `object` writes. Example finding: ```text fields.contact.dependsOn[0].param "account_label" is a formula field of "showcase_contact", computed on read: no record-picker query or import lookup can filter on it. ``` The hint names the fix: point the entry at a stored field of the referenced object that holds the same value, in the `{ field, param }` form, or drop it. A formula on the OWNING side (`dependsOn[i].field`, the form's gate, read from the record being edited) stays legal. `os explain object-field-ref-unknown` (`rule-explanations.ts`) gains one sentence for it; the module note says what is judged and why. - **`@objectstack/core`, N4: no unscoped probe when no scoped read answered.** The import resolver (`import-runner.ts`) now marks every scoped lookup none of whose candidate reads answered, and the field guard did not refuse, as `RefMatch.scopeUnanswered` when the refusals did not name an unfilterable scope field (that case keeps `scopeUnqueryable`). `referenceNotFound` (`import-coerce.ts`) returns the plain `reference_not_found` refusal for it before the unscoped probe. Before, an all-refused scoped lookup (for example every read refused `INVALID_FILTER` because the row's master cell is a value the scoping field's type cannot take) was asked again without the scope and could answer `reference_out_of_scope`, a claim about where the value lives that the import never checked. `RefMatch` gains the optional member `scopeUnanswered`. - **Wording (N4).** The `validation-message.ts` jsdoc on `import_reference_scope_unqueryable` and the `import-mappings.mdx` paragraph now say that any other all-refused scoped lookup keeps `reference_not_found` and the plain sentence and is not tried again without the scope. The docs paragraph also says the formula case is refused at authoring now. - **Upgrade guide.** New ADR-0087 semantic entry `lookup-depends-on-param-computed-field-refused` (`packages/spec/src/migrations/entries/semantic/`), notice only: no D2 conversion, since only the author knows which stored field carries the value the formula computes. - **Changeset** `.changeset/37717-lookup-depends-on-param-computed-field.md`: `@objectstack/lint` minor (the narrowing), `@objectstack/core` and `@objectstack/spec` patch, BREAKING banner, FROM → TO, `registered` disposition. The pending note `.changeset/36794-wizard-reference-out-of-scope.md` is left as it is: its sentence "A scoped lookup whose reads are all refused for any other reason (no read access to the target, say) keeps the plain `no record matches` sentence." was loose on `main` (review N4) and is exactly true after this change, so it is not rewritten. ### Small choices made here (dev's call, per the claim) - One rule id, `object-field-ref-unknown`, not a new one. The roll-up filter position in the same rule already refuses a key computed on read under that id, and the rule already runs at error on every door this needs, so no new registration, explanation entry or door wiring was added. - Population: fields computed on read only (`SEARCH_VIRTUAL_TYPES`, today `formula`), which is what the card names. A `secret` / `password` field, or one flagged `internal: true`, is also refused as a filter key for a non-system caller, but by a guard that judges the caller, not the field's storage; left out (see Acceptance notes). - N4 covers every all-refused scoped lookup, not only `INVALID_FILTER`: whatever refused every scoped read, the scope was never asked, so a hit without it says nothing about the scope. ## Tests - `packages/lint/src/validate-object-field-refs.test.ts`, in the `dependsOn` describe: a `param` naming a formula of the referenced object is refused at `.param` with the field and the reason; a bare name that is a formula on the referenced side is refused at the entry; a stored `param`, and a formula on the owning side only, pass; the runtime publish gate refuses it too (`objects.crm_invoice.fields.contact.dependsOn[0].param`). The file's own 200-character cap on every fired verdict still holds. - `packages/core/src/utils/import-runner-reference-master-scope.test.ts`: every scoped read refused `INVALID_FILTER` while the unscoped read would answer with a record under another project; the cell answers `reference_not_found`, the plain sentence, no `scope`, and every read of the target carried the scope (no unscoped probe). - Ablations (tree `40007bc2`, through `scripts/ablation-replace.mjs`, each restored to the `HEAD` blob with `git diff HEAD` empty): - runner: `{ scopeUnanswered: true }` → `{}`: the N4 pin goes red (`reference_out_of_scope` received), 1 failed / 19 passed; restored 20 passed. - coerce: the `scopeUnanswered` early return deleted: the same pin red, 1 failed / 19 passed. - lint: the `filtered` branch disabled: 3 failed / 128 passed (the two refusals and the runtime-gate pin); restored 131 passed. ## Acceptance notes - First-party exposure, measured: `objectstack validate` passes on all five example apps (`app-crm`, `app-showcase`, `app-starter`, `app-todo`, `app-multi-package`) with the new rule built in. Positive control on the same CLI: adding a formula `account_label` to `showcase_contact` and pointing `showcase_invoice.contact`'s `dependsOn` `param` at it exits 1 with the finding quoted above (both mutations restored). By reading, every other shipped `dependsOn` is clean: the five in `plugin-sharing` sit on `text` / non-picker fields, where the filter half has no reader and is not judged; every one in hotcrm (`crm_account`, `crm_project`) names a `lookup` / `master_detail` field of its target. - Not judged here, for a later card if anyone wants it: a `dependsOn` filter key naming a `secret` / `password` field or an `internal: true` field. Those are refused as filters for non-system callers by the credential and internal-field guards, a judgment about the caller, not about the field's storage. - A stored object that already carries such an entry is not refused at boot. Its import keeps the could-not-look-up sentence from #37706, and its next publish is refused. ## Verification Read first: the `filtered` branch in `validateObjectFieldRefs` (`validate-object-field-refs.ts`), the all-refused branch at the end of the resolver's `lookup` (`import-runner.ts`), and the `scopeUnanswered` return in `referenceNotFound` (`import-coerce.ts`). Two-minute check: `pnpm --filter @objectstack/lint exec vitest run src/validate-object-field-refs.test.ts -t "formula"` runs 3 tests, all green. <details><summary>Local readings (tree 40007bc, on main 1e721fd)</summary> - `@objectstack/lint` whole package: 242 files / 9801 passed. `@objectstack/core` whole package: 166 files / 3902 passed. - `typecheck` lint, core and spec: green. `eslint --no-inline-config` on the eight changed source files: 0 problems. - `objectstack validate`: all five example apps pass; the positive control exits 1 with the new finding. - The derived local gate sweep (`dispatch-gates.mjs --commands`, 119 commands, tree 40007bc): 116 exit 0. Three exit 3, prerequisite not met, NOT measured: `check-plugin-teardown-shape --self-test` (shallow clone), `spec check:skill-examples` (client-react not built), `check:dual-build-cjs-loads`; CI covers these families on this head. `check:type-check-debt` first queued behind the dogfood hold, then re-run under the lock: exit 0, 0 ledger entries above their number. - Dogfood battery on 40007bc under `os-verify-lock`: VERDICT command-exit 0, Test Files 490 passed / 3 skipped (493), Tests 4144 passed / 68 skipped (4212), no failures. - CI on 40007bc: 60 check-runs success, 10 skipped, none failed. </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [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. - [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. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgXj9vLmZ3KE2rWhtBH --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgXj9vLmZ3KE2rWhtBH)_ <!-- signed: repo:objectstack#2 · os-sales · session_01L6bhgXj9vLmZ3KE2rWhtBH --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 39fafc0 commit 709a087

10 files changed

Lines changed: 232 additions & 10 deletions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
'@objectstack/lint': minor
3+
'@objectstack/core': patch
4+
'@objectstack/spec': patch
5+
---
6+
7+
fix(lint,core)!: a lookup `dependsOn` entry whose filter key names a formula of the referenced object is refused at authoring; an import lookup none of whose scoped reads answered is never reported as out of scope
8+
9+
Clause-②: yes (narrowing) — a lookup, master_detail or user field whose `dependsOn` filter key names a field of the referenced object computed on read (a `formula`) publishes today and is now refused at `error` by `object-field-ref-unknown`
10+
Metadata-protocol: narrowed — a `dependsOn` filter key naming a field of the referenced object computed on read is refused at authoring
11+
Skills-docs: none — no published skill page teaches a `dependsOn` filter key on a formula
12+
13+
<!-- adr-0087: registered lookup-depends-on-param-computed-field-refused -->
14+
15+
**BREAKING** for the publish of an object with such a `dependsOn` entry: it was accepted before and is refused now, by `objectstack validate` / `lint` / `compile` / `build` and by the runtime publish gate, with the field and the fix named in the finding. The schema is unchanged, and stored objects are not rewritten or refused at boot; the refusal comes at the next publish.
16+
17+
**Why.** The record picker filters its candidates, and the importer scopes a lookup cell, by the entry's filter key on the referenced object (`param` in `{ field, param }`, else the bare name or `field`). The engine refuses every filter on a field computed on read, so such an entry published clean, then every picker query it scoped was refused and every import of the column failed its lookup. The finding names the referenced field and why it cannot be filtered on, for example `fields.task.dependsOn[0].param "project_label" is a formula field of "oos_task", computed on read: no record-picker query or import lookup can filter on it.`
18+
19+
## FROM → TO
20+
21+
- `dependsOn: [{ field: 'project', param: 'project_label' }]`, where `project_label` is a formula of the referenced object → `dependsOn: [{ field: 'project', param: 'project' }]`, naming the stored field of the referenced object that holds the same value; or drop the entry.
22+
- `dependsOn: ['region']`, where `region` is a formula on the referenced object → `dependsOn: [{ field: 'region', param: 'region_code' }]` with `region_code` a stored field of the referenced object.
23+
24+
A formula on the OWNING object stays a legal gate (`dependsOn[i].field`): the form reads it from the record being edited.
25+
26+
**`@objectstack/core`, the importer.** A scoped lookup none of whose reads answered (every read refused, for example because the row's master cell is a value the scoping field's type cannot take) is no longer asked again without the scope. It keeps `reference_not_found` and the plain `no record matches` sentence, and never answers `reference_out_of_scope`, which it could before when the value matched a record outside the scope. `RefMatch` gains the optional member `scopeUnanswered`, which a resolver sets for such a lookup.
27+
28+
Measured first-party exposure: none. Every `dependsOn` in `examples/` and in the packaged objects names a stored field on the referenced side, or sits on a field type with no picker.
29+
30+
`@objectstack/spec` adds only the upgrade-guide entry `lookup-depends-on-param-computed-field-refused`.

‎content/docs/data-modeling/import-mappings.mdx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,15 @@ A `dependsOn` entry whose `param` names a target field the engine cannot filter
374374
fails with `reference_not_found` and a sentence that says the lookup could not be made within
375375
the scope and names the cause (`Task: "Design review" could not be looked up within Project =
376376
"Gemini": the target field this lookup's dependsOn filters by cannot be filtered on, …`),
377-
never `reference_out_of_scope`. Point `param` at a stored field of the target. A scoped
378-
lookup whose reads are refused for any other reason, such as no read access to the target,
379-
keeps the plain `no record matches` sentence.
377+
never `reference_out_of_scope`. Point `param` at a stored field of the target. `os validate`
378+
and the runtime publish gate refuse such an entry at authoring (`object-field-ref-unknown`,
379+
naming the target field), so an import meets this sentence only on metadata stored before that
380+
check.
381+
382+
A scoped lookup whose reads are all refused for any other reason, such as no read access to
383+
the target or a master cell the scoping field's type cannot take, keeps `reference_not_found`
384+
and the plain `no record matches` sentence: the lookup is not tried again without the scope,
385+
so it never answers `reference_out_of_scope`.
380386

381387
A pasted id is scoped too, so a row that means another master's detail cannot be linked
382388
in one import. Correct the master cell; or, when the cross-master link is intended, leave

‎packages/core/src/utils/import-coerce.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ export interface RefMatch {
105105
* within the row's scope, never that the value lives under another parent.
106106
*/
107107
scopeUnqueryable?: boolean;
108+
/**
109+
* [#37717] The SCOPED lookup asked nothing for any other reason: no candidate
110+
* read answered, and no refusal said the scope's target field cannot be
111+
* filtered by or read (a comparand the field's type cannot take, a missing
112+
* read grant, a driver fault). Nothing is known about where the value lives,
113+
* so it is not asked again without the scope: the refusal stays
114+
* `reference_not_found` with the plain sentence, never
115+
* `reference_out_of_scope`.
116+
*/
117+
scopeUnanswered?: boolean;
108118
}
109119

110120
/**
@@ -191,7 +201,12 @@ interface ScopedBy {
191201
* refused the scope (`RefMatch.scopeUnqueryable`: the scope names a target field
192202
* the engine cannot filter by, such as a formula) is not probed either: it
193203
* stays `reference_not_found` with its own sentence, which says the lookup
194-
* could not be made within the row's scope.
204+
* could not be made within the row's scope. [#37717] Nor is a scoped lookup
205+
* none of whose reads answered for any other reason
206+
* (`RefMatch.scopeUnanswered`: every read refused, say for a scope cell the
207+
* field's type cannot take): only a scoped read that ran to a miss says the
208+
* value is not within the scope, so that cell stays `reference_not_found` with
209+
* the plain sentence.
195210
*
196211
* The probe is the caller's own read: the resolver runs every lookup as the
197212
* importing principal, so it can find only a record that principal can already
@@ -213,6 +228,9 @@ async function referenceNotFound(
213228
// A scope the caller may not filter by was never asked: nothing is known about
214229
// where the value lives, so it is not "under another parent".
215230
if (scopedMatch.scopeDenied) return refusal;
231+
// [#37717] No scoped read answered (every one refused): the scope was never
232+
// asked, so a hit without it would claim a fact the import never checked.
233+
if (scopedMatch.scopeUnanswered) return refusal;
216234
const qualifier = scopedBy.map((s) => `${s.label} = "${s.value}"`).join(', ');
217235
// A scope no read could filter by: say the lookup could not be made, not that nothing matched.
218236
if (scopedMatch.scopeUnqueryable) {

‎packages/core/src/utils/import-runner-reference-master-scope.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,31 @@ describe('[#36159] [#36794] a scoped miss whose value exists outside the row\'s
397397
]);
398398
});
399399

400+
it('[#37717] a scoped lookup none of whose reads answered is never probed unscoped: a value the scope cell\'s type cannot take keeps the plain sentence', async () => {
401+
const { p, findData } = protocol();
402+
// Every read carrying the scope is refused for the scope cell's value
403+
// (INVALID_FILTER, a comparand the field's type cannot take); a read
404+
// without the scope would answer. "Design review" exists, under Apollo.
405+
findData.mockImplementation(async (args: FindArgs) => {
406+
const where = args.query!.where as Record<string, unknown>;
407+
if (args.object === 'xm_task' && 'project' in where) {
408+
throw Object.assign(new Error("ObjectQL.find('xm_task'): 'project' cannot take that value"), {
409+
code: 'INVALID_FILTER', status: 400, field: 'project',
410+
});
411+
}
412+
return (ROWS[args.object] ?? []).filter((r) => matches(r, where));
413+
});
414+
const summary = await run(p, [{ name: 'INV-1', project: 'Gemini', task: 'Design review' }]);
415+
expect(summary.results.map(refusal)).toEqual([
416+
{ ok: false, code: 'reference_not_found', field: 'task', error: 'task: no record matches "Design review"' },
417+
]);
418+
expect(summary.results.map(cellErrors)).toEqual([[{ field: 'task', code: 'reference_not_found', scope: undefined }]]);
419+
// No unscoped probe ran: every xm_task read carried the scope.
420+
const taskReads = findData.mock.calls.map(([c]) => c).filter((c) => c.object === 'xm_task');
421+
expect(taskReads.length).toBeGreaterThan(0);
422+
for (const c of taskReads) expect(c.query!.where).toHaveProperty('project');
423+
});
424+
400425
it('the unscoped probe is the importing caller\'s own read, and a record that caller cannot read stays unnamed', async () => {
401426
const { p, findData } = protocol();
402427
// The caller's reads see no Apollo task: the fake hides xm_task rows of p1

‎packages/core/src/utils/import-runner.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,9 +1044,13 @@ export function runImport(opts: RunImportOptions): Promise<ImportRunSummary> {
10441044
/* field absent on target object — try the next candidate */
10451045
}
10461046
}
1047-
// Any other refusal (no read grant on the target, a driver fault) keeps the
1048-
// plain miss: nothing says the scope column was the cause.
1049-
if (scope && !asked && scopeUnfilterable && !match.scopeDenied) match = { scopeUnqueryable: true };
1047+
// Any other refusal (no read grant on the target, a driver fault, a scope
1048+
// cell the field's type cannot take) keeps the plain sentence: nothing says
1049+
// the scope column was the cause. [#37717] It is still a lookup that asked
1050+
// nothing, so it is marked as one and never probed without the scope.
1051+
if (scope && !asked && !match.scopeDenied) {
1052+
match = scopeUnfilterable ? { scopeUnqueryable: true } : { scopeUnanswered: true };
1053+
}
10501054
return match;
10511055
};
10521056
let match = await lookup();

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4768,7 +4768,11 @@ const OBJECT_FIELD_REF_UNKNOWN_EXPLANATION: RuleExplanation = {
47684768
'against the referenced object ' +
47694769
'(the picker scopes its candidates by that key). The referenced object is judged only on ' +
47704770
'`lookup`, `master_detail` and `user` fields, the types that render the picker, and a bare ' +
4771-
'`dependsOn` name that misses on the owning object is reported once, there.',
4771+
'`dependsOn` name that misses on the owning object is reported once, there. The `dependsOn` ' +
4772+
'filter key is refused too when it names a field of the referenced object computed on read, ' +
4773+
'such as a `formula`: the engine cannot filter on it, so every picker query the entry scopes is ' +
4774+
'refused and an import of the column fails every lookup (point it at a stored field holding ' +
4775+
'the same value).',
47724776
'On those picker fields a `lookupFilters[].value.$record` path is judged too, against the record ' +
47734777
'being edited: a field of the object that owns the picker field, or at most one relationship hop ' +
47744778
'from it (a ' +

‎packages/lint/src/validate-object-field-refs.test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,69 @@ describe('validateObjectFieldRefs — dependsOn (the gate on the OWNER, the filt
11281128
expect(findings[0]!.message).toContain('Did you mean "country"?');
11291129
});
11301130

1131+
// [#37717] The filter half names a field the referenced object computes on
1132+
// read: the engine refuses every filter on it, so the picker's candidate
1133+
// query and the importer's scoped lookup both get no answer.
1134+
const withFormula = (fields: Record<string, unknown>) => ({
1135+
objects: [
1136+
invoice(fields),
1137+
account({ fields: {
1138+
...account().fields,
1139+
region_label: { type: 'formula', expression: 'UPPER(region)' },
1140+
} }),
1141+
],
1142+
});
1143+
1144+
it('REFUSES a `param` naming a formula field of the referenced object, naming that field and why', () => {
1145+
const findings = validateObjectFieldRefs(withFormula({
1146+
region_label: { type: 'text' },
1147+
contact: lookup({ dependsOn: [{ field: 'region', param: 'region_label' }] }),
1148+
}));
1149+
expect(findings).toHaveLength(1);
1150+
expect(findings[0]).toMatchObject({
1151+
severity: 'error',
1152+
rule: OBJECT_FIELD_REF_UNKNOWN,
1153+
path: 'objects[0].fields.contact.dependsOn[0].param',
1154+
});
1155+
expect(findings[0]!.message).toContain('"region_label" is a formula field of "crm_account", computed on read');
1156+
expect(findings[0]!.hint).toContain('stored field of the referenced object');
1157+
expect(explained()).toContain('computed on read, such as a `formula`');
1158+
});
1159+
1160+
it('REFUSES a bare name that is a formula on the referenced object — it is the filter key too', () => {
1161+
const findings = validateObjectFieldRefs(withFormula({
1162+
region_label: { type: 'text' },
1163+
contact: lookup({ dependsOn: ['region_label'] }),
1164+
}));
1165+
expect(findings.map((f) => f.path)).toEqual(['objects[0].fields.contact.dependsOn[0]']);
1166+
expect(findings[0]!.message).toContain('computed on read');
1167+
});
1168+
1169+
it('passes a `param` naming a stored field, and a formula only on the OWNING side (the gate reads the record)', () => {
1170+
expect(validateObjectFieldRefs(withFormula({
1171+
contact: lookup({ dependsOn: [{ field: 'region', param: 'region' }] }),
1172+
}))).toEqual([]);
1173+
expect(validateObjectFieldRefs(withFormula({
1174+
region_calc: { type: 'formula', expression: 'region' },
1175+
contact: lookup({ dependsOn: [{ field: 'region_calc', param: 'region' }] }),
1176+
}))).toEqual([]);
1177+
});
1178+
1179+
it('is refused at the runtime publish gate too', () => {
1180+
const stack = withFormula({
1181+
region_label: { type: 'text' },
1182+
contact: lookup({ dependsOn: [{ field: 'region', param: 'region_label' }] }),
1183+
});
1184+
const result = runRuntimeAuthoringRules({
1185+
type: 'object',
1186+
item: stack.objects[0],
1187+
context: { objects: [stack.objects[1]] },
1188+
});
1189+
const refusal = result.errors.find((f) => f.rule === OBJECT_FIELD_REF_UNKNOWN);
1190+
expect(refusal, JSON.stringify(result.errors)).toBeDefined();
1191+
expect(refusal!.path).toBe('objects.crm_invoice.fields.contact.dependsOn[0].param');
1192+
});
1193+
11311194
it('a registry-injected column on the owner is a live gate (skip 3)', () => {
11321195
expect(validateObjectFieldRefs({ objects: [invoice({
11331196
note: { type: 'text', dependsOn: ['owner_id'] },

‎packages/lint/src/validate-object-field-refs.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@
127127
* unresolved-`$record` refusal belongs to the server door that meets it.
128128
* - **`dependsOn[]`** (both arms: a name, or `{ field, param }`) — the fields
129129
* whose values gate this field and, on a picker, scope its candidates.
130+
* The filter half (`param`, or the bare name) is also refused when it names
131+
* a field of the referenced object computed on read (a `formula`,
132+
* `isVirtualSearchField`, #37717): the picker's candidate query and the
133+
* importer's scoped lookup filter by it, and the engine's filter seam
134+
* refuses every such filter, so the picker gets no answer and every import
135+
* of the column fails its lookup.
130136
* - **`summaryOperations.filter`** — every field key of a roll-up's child-row
131137
* predicate (#31224), judged against the CHILD object
132138
* `summaryOperations.object` names, never the object that owns the summary
@@ -498,6 +504,15 @@ interface FieldNameSlot {
498504
singleValued?: boolean;
499505
/** [#34378] The hint when {@link singleValued} refuses a path. */
500506
singleValuedPrescription?: string;
507+
/**
508+
* [#37717] `true` when the reader FILTERS by the name: a name that resolves
509+
* to a field computed on read (`isVirtualSearchField`, the predicate the
510+
* engine's filter seam refuses by) has no column to filter, so it is refused
511+
* too. Judged only on an AUTHORED field of the addressed object.
512+
*/
513+
filtered?: boolean;
514+
/** [#37717] The hint when {@link filtered} refuses a name. */
515+
filteredPrescription?: string;
501516
}
502517

503518
function nameOf(v: unknown): string | undefined {
@@ -601,6 +616,15 @@ const FIELD_NAME_SLOTS: readonly FieldNameSlot[] = [
601616
'When the two sides are spelled differently, write the entry as '
602617
+ '`{ field: \'this_record_field\', param: \'referenced_object_field\' }`; otherwise fix '
603618
+ 'the name.',
619+
// [#37717] The picker's candidate query and the importer's scoped lookup
620+
// both filter the referenced object by this key, and the engine refuses
621+
// every filter on a field computed on read: the picker then lists nothing
622+
// and every import of the column fails its lookup.
623+
filtered: true,
624+
filteredPrescription:
625+
'Point the entry at a stored field of the referenced object that holds the same value, '
626+
+ 'written as `{ field: \'this_record_field\', param: \'stored_referenced_field\' }`, or drop '
627+
+ 'the entry.',
604628
},
605629
];
606630

@@ -1023,6 +1047,21 @@ export function validateObjectFieldRefs(stack: AnyRec): ObjectFieldRefFinding[]
10231047
});
10241048
if (hit && !slot.ownFinding) reported.add(`${at}=${read.name}`);
10251049

1050+
// [#37717] A name the reader filters by must name a field it can
1051+
// filter: one computed on read has no column, so the engine refuses
1052+
// the filter and the reader gets no answer at all.
1053+
if (!hit && slot.filtered) {
1054+
const named = graph.get(against)?.fields.get(read.name);
1055+
if (named && isVirtualSearchField(named as never)) {
1056+
refuseKey(
1057+
{ where, path },
1058+
`${subject} "${read.name}" is a ${named.type} field of "${against}", computed on read: `
1059+
+ 'no record-picker query or import lookup can filter on it.',
1060+
slot.filteredPrescription ?? slot.prescription,
1061+
);
1062+
}
1063+
}
1064+
10261065
// [#34378] A path that names real fields can still read a LIST: a
10271066
// multi-valued head, or a multi-valued leaf behind one hop. The
10281067
// comparand is one value under a scalar operator, so it is refused.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
import type { SemanticMigration } from '../../types.js';
4+
5+
// A lookup's `dependsOn` filter key is judged against what the engine can
6+
// filter: a field of the referenced object computed on read (a `formula`) has
7+
// no column, so every picker query and every import lookup the entry scopes is
8+
// refused. Semantic-only — which stored field holds the value the author meant
9+
// to scope by is the author's call, so no D2 conversion rewrites it.
10+
export const entry: SemanticMigration = {
11+
id: 'lookup-depends-on-param-computed-field-refused',
12+
surface:
13+
'object.fields.<field>.dependsOn[] on a lookup, master_detail or user field — the filter key the entry '
14+
+ 'scopes the referenced object by (`param` in the { field, param } form, else the bare name or `field`), '
15+
+ 'when it names a field of the referenced object computed on read (a formula)',
16+
replacement:
17+
'a stored field of the referenced object that holds the same value, written as { field: '
18+
+ '\'this_record_field\', param: \'stored_referenced_field\' }; or drop the entry when the picker need not '
19+
+ 'be scoped.',
20+
reason:
21+
'The record picker filters its candidates, and the importer scopes a lookup cell, by this key on the '
22+
+ 'referenced object, and the engine refuses every filter on a field computed on read. Such an entry '
23+
+ 'published clean, then every picker query it scoped was refused and every import of the column failed '
24+
+ 'its lookup. object-field-ref-unknown now reports it as an error, on objectstack validate and at the '
25+
+ 'runtime publish gate. No D2 conversion exists: only the author knows which stored field carries the '
26+
+ 'value the formula computes.',
27+
acceptanceCriteria:
28+
'Run objectstack validate: no object-field-ref-unknown finding says a dependsOn entry names a field '
29+
+ 'computed on read. For each entry it named, the filter key is a stored field of the referenced object, or '
30+
+ 'the entry is gone, and the record picker lists candidates once the field it depends on has a value.',
31+
};

0 commit comments

Comments
 (0)