Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .changeset/37717-lookup-depends-on-param-computed-field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
'@objectstack/lint': minor
'@objectstack/core': patch
'@objectstack/spec': patch
---

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

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`
Metadata-protocol: narrowed — a `dependsOn` filter key naming a field of the referenced object computed on read is refused at authoring
Skills-docs: none — no published skill page teaches a `dependsOn` filter key on a formula

<!-- adr-0087: registered lookup-depends-on-param-computed-field-refused -->

**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.

**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.`

## FROM → TO

- `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.
- `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.

A formula on the OWNING object stays a legal gate (`dependsOn[i].field`): the form reads it from the record being edited.

**`@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.

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.

`@objectstack/spec` adds only the upgrade-guide entry `lookup-depends-on-param-computed-field-refused`.
12 changes: 9 additions & 3 deletions content/docs/data-modeling/import-mappings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,15 @@ A `dependsOn` entry whose `param` names a target field the engine cannot filter
fails with `reference_not_found` and a sentence that says the lookup could not be made within
the scope and names the cause (`Task: "Design review" could not be looked up within Project =
"Gemini": the target field this lookup's dependsOn filters by cannot be filtered on, …`),
never `reference_out_of_scope`. Point `param` at a stored field of the target. A scoped
lookup whose reads are refused for any other reason, such as no read access to the target,
keeps the plain `no record matches` sentence.
never `reference_out_of_scope`. Point `param` at a stored field of the target. `os validate`
and the runtime publish gate refuse such an entry at authoring (`object-field-ref-unknown`,
naming the target field), so an import meets this sentence only on metadata stored before that
check.

A scoped lookup whose reads are all refused for any other reason, such as no read access to
the target or a master cell the scoping field's type cannot take, keeps `reference_not_found`
and the plain `no record matches` sentence: the lookup is not tried again without the scope,
so it never answers `reference_out_of_scope`.

A pasted id is scoped too, so a row that means another master's detail cannot be linked
in one import. Correct the master cell; or, when the cross-master link is intended, leave
Expand Down
20 changes: 19 additions & 1 deletion packages/core/src/utils/import-coerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ export interface RefMatch {
* within the row's scope, never that the value lives under another parent.
*/
scopeUnqueryable?: boolean;
/**
* [#37717] The SCOPED lookup asked nothing for any other reason: no candidate
* read answered, and no refusal said the scope's target field cannot be
* filtered by or read (a comparand the field's type cannot take, a missing
* read grant, a driver fault). Nothing is known about where the value lives,
* so it is not asked again without the scope: the refusal stays
* `reference_not_found` with the plain sentence, never
* `reference_out_of_scope`.
*/
scopeUnanswered?: boolean;
}

/**
Expand Down Expand Up @@ -191,7 +201,12 @@ interface ScopedBy {
* refused the scope (`RefMatch.scopeUnqueryable`: the scope names a target field
* the engine cannot filter by, such as a formula) is not probed either: it
* stays `reference_not_found` with its own sentence, which says the lookup
* could not be made within the row's scope.
* could not be made within the row's scope. [#37717] Nor is a scoped lookup
* none of whose reads answered for any other reason
* (`RefMatch.scopeUnanswered`: every read refused, say for a scope cell the
* field's type cannot take): only a scoped read that ran to a miss says the
* value is not within the scope, so that cell stays `reference_not_found` with
* the plain sentence.
*
* The probe is the caller's own read: the resolver runs every lookup as the
* importing principal, so it can find only a record that principal can already
Expand All @@ -213,6 +228,9 @@ async function referenceNotFound(
// A scope the caller may not filter by was never asked: nothing is known about
// where the value lives, so it is not "under another parent".
if (scopedMatch.scopeDenied) return refusal;
// [#37717] No scoped read answered (every one refused): the scope was never
// asked, so a hit without it would claim a fact the import never checked.
if (scopedMatch.scopeUnanswered) return refusal;
const qualifier = scopedBy.map((s) => `${s.label} = "${s.value}"`).join(', ');
// A scope no read could filter by: say the lookup could not be made, not that nothing matched.
if (scopedMatch.scopeUnqueryable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,31 @@ describe('[#36159] [#36794] a scoped miss whose value exists outside the row\'s
]);
});

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 () => {
const { p, findData } = protocol();
// Every read carrying the scope is refused for the scope cell's value
// (INVALID_FILTER, a comparand the field's type cannot take); a read
// without the scope would answer. "Design review" exists, under Apollo.
findData.mockImplementation(async (args: FindArgs) => {
const where = args.query!.where as Record<string, unknown>;
if (args.object === 'xm_task' && 'project' in where) {
throw Object.assign(new Error("ObjectQL.find('xm_task'): 'project' cannot take that value"), {
code: 'INVALID_FILTER', status: 400, field: 'project',
});
}
return (ROWS[args.object] ?? []).filter((r) => matches(r, where));
});
const summary = await run(p, [{ name: 'INV-1', project: 'Gemini', task: 'Design review' }]);
expect(summary.results.map(refusal)).toEqual([
{ ok: false, code: 'reference_not_found', field: 'task', error: 'task: no record matches "Design review"' },
]);
expect(summary.results.map(cellErrors)).toEqual([[{ field: 'task', code: 'reference_not_found', scope: undefined }]]);
// No unscoped probe ran: every xm_task read carried the scope.
const taskReads = findData.mock.calls.map(([c]) => c).filter((c) => c.object === 'xm_task');
expect(taskReads.length).toBeGreaterThan(0);
for (const c of taskReads) expect(c.query!.where).toHaveProperty('project');
});

it('the unscoped probe is the importing caller\'s own read, and a record that caller cannot read stays unnamed', async () => {
const { p, findData } = protocol();
// The caller's reads see no Apollo task: the fake hides xm_task rows of p1
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/utils/import-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,9 +1044,13 @@ export function runImport(opts: RunImportOptions): Promise<ImportRunSummary> {
/* field absent on target object — try the next candidate */
}
}
// Any other refusal (no read grant on the target, a driver fault) keeps the
// plain miss: nothing says the scope column was the cause.
if (scope && !asked && scopeUnfilterable && !match.scopeDenied) match = { scopeUnqueryable: true };
// Any other refusal (no read grant on the target, a driver fault, a scope
// cell the field's type cannot take) keeps the plain sentence: nothing says
// the scope column was the cause. [#37717] It is still a lookup that asked
// nothing, so it is marked as one and never probed without the scope.
if (scope && !asked && !match.scopeDenied) {
match = scopeUnfilterable ? { scopeUnqueryable: true } : { scopeUnanswered: true };
}
return match;
};
let match = await lookup();
Expand Down
6 changes: 5 additions & 1 deletion packages/lint/src/rule-explanations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4768,7 +4768,11 @@ const OBJECT_FIELD_REF_UNKNOWN_EXPLANATION: RuleExplanation = {
'against the referenced object ' +
'(the picker scopes its candidates by that key). The referenced object is judged only on ' +
'`lookup`, `master_detail` and `user` fields, the types that render the picker, and a bare ' +
'`dependsOn` name that misses on the owning object is reported once, there.',
'`dependsOn` name that misses on the owning object is reported once, there. The `dependsOn` ' +
'filter key is refused too when it names a field of the referenced object computed on read, ' +
'such as a `formula`: the engine cannot filter on it, so every picker query the entry scopes is ' +
'refused and an import of the column fails every lookup (point it at a stored field holding ' +
'the same value).',
'On those picker fields a `lookupFilters[].value.$record` path is judged too, against the record ' +
'being edited: a field of the object that owns the picker field, or at most one relationship hop ' +
'from it (a ' +
Expand Down
63 changes: 63 additions & 0 deletions packages/lint/src/validate-object-field-refs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,69 @@ describe('validateObjectFieldRefs — dependsOn (the gate on the OWNER, the filt
expect(findings[0]!.message).toContain('Did you mean "country"?');
});

// [#37717] The filter half names a field the referenced object computes on
// read: the engine refuses every filter on it, so the picker's candidate
// query and the importer's scoped lookup both get no answer.
const withFormula = (fields: Record<string, unknown>) => ({
objects: [
invoice(fields),
account({ fields: {
...account().fields,
region_label: { type: 'formula', expression: 'UPPER(region)' },
} }),
],
});

it('REFUSES a `param` naming a formula field of the referenced object, naming that field and why', () => {
const findings = validateObjectFieldRefs(withFormula({
region_label: { type: 'text' },
contact: lookup({ dependsOn: [{ field: 'region', param: 'region_label' }] }),
}));
expect(findings).toHaveLength(1);
expect(findings[0]).toMatchObject({
severity: 'error',
rule: OBJECT_FIELD_REF_UNKNOWN,
path: 'objects[0].fields.contact.dependsOn[0].param',
});
expect(findings[0]!.message).toContain('"region_label" is a formula field of "crm_account", computed on read');
expect(findings[0]!.hint).toContain('stored field of the referenced object');
expect(explained()).toContain('computed on read, such as a `formula`');
});

it('REFUSES a bare name that is a formula on the referenced object — it is the filter key too', () => {
const findings = validateObjectFieldRefs(withFormula({
region_label: { type: 'text' },
contact: lookup({ dependsOn: ['region_label'] }),
}));
expect(findings.map((f) => f.path)).toEqual(['objects[0].fields.contact.dependsOn[0]']);
expect(findings[0]!.message).toContain('computed on read');
});

it('passes a `param` naming a stored field, and a formula only on the OWNING side (the gate reads the record)', () => {
expect(validateObjectFieldRefs(withFormula({
contact: lookup({ dependsOn: [{ field: 'region', param: 'region' }] }),
}))).toEqual([]);
expect(validateObjectFieldRefs(withFormula({
region_calc: { type: 'formula', expression: 'region' },
contact: lookup({ dependsOn: [{ field: 'region_calc', param: 'region' }] }),
}))).toEqual([]);
});

it('is refused at the runtime publish gate too', () => {
const stack = withFormula({
region_label: { type: 'text' },
contact: lookup({ dependsOn: [{ field: 'region', param: 'region_label' }] }),
});
const result = runRuntimeAuthoringRules({
type: 'object',
item: stack.objects[0],
context: { objects: [stack.objects[1]] },
});
const refusal = result.errors.find((f) => f.rule === OBJECT_FIELD_REF_UNKNOWN);
expect(refusal, JSON.stringify(result.errors)).toBeDefined();
expect(refusal!.path).toBe('objects.crm_invoice.fields.contact.dependsOn[0].param');
});

it('a registry-injected column on the owner is a live gate (skip 3)', () => {
expect(validateObjectFieldRefs({ objects: [invoice({
note: { type: 'text', dependsOn: ['owner_id'] },
Expand Down
39 changes: 39 additions & 0 deletions packages/lint/src/validate-object-field-refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@
* unresolved-`$record` refusal belongs to the server door that meets it.
* - **`dependsOn[]`** (both arms: a name, or `{ field, param }`) — the fields
* whose values gate this field and, on a picker, scope its candidates.
* The filter half (`param`, or the bare name) is also refused when it names
* a field of the referenced object computed on read (a `formula`,
* `isVirtualSearchField`, #37717): the picker's candidate query and the
* importer's scoped lookup filter by it, and the engine's filter seam
* refuses every such filter, so the picker gets no answer and every import
* of the column fails its lookup.
* - **`summaryOperations.filter`** — every field key of a roll-up's child-row
* predicate (#31224), judged against the CHILD object
* `summaryOperations.object` names, never the object that owns the summary
Expand Down Expand Up @@ -498,6 +504,15 @@ interface FieldNameSlot {
singleValued?: boolean;
/** [#34378] The hint when {@link singleValued} refuses a path. */
singleValuedPrescription?: string;
/**
* [#37717] `true` when the reader FILTERS by the name: a name that resolves
* to a field computed on read (`isVirtualSearchField`, the predicate the
* engine's filter seam refuses by) has no column to filter, so it is refused
* too. Judged only on an AUTHORED field of the addressed object.
*/
filtered?: boolean;
/** [#37717] The hint when {@link filtered} refuses a name. */
filteredPrescription?: string;
}

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

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

// [#37717] A name the reader filters by must name a field it can
// filter: one computed on read has no column, so the engine refuses
// the filter and the reader gets no answer at all.
if (!hit && slot.filtered) {
const named = graph.get(against)?.fields.get(read.name);
if (named && isVirtualSearchField(named as never)) {
refuseKey(
{ where, path },
`${subject} "${read.name}" is a ${named.type} field of "${against}", computed on read: `
+ 'no record-picker query or import lookup can filter on it.',
slot.filteredPrescription ?? slot.prescription,
);
}
}

// [#34378] A path that names real fields can still read a LIST: a
// multi-valued head, or a multi-valued leaf behind one hop. The
// comparand is one value under a scalar operator, so it is refused.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import type { SemanticMigration } from '../../types.js';

// A lookup's `dependsOn` filter key is judged against what the engine can
// filter: a field of the referenced object computed on read (a `formula`) has
// no column, so every picker query and every import lookup the entry scopes is
// refused. Semantic-only — which stored field holds the value the author meant
// to scope by is the author's call, so no D2 conversion rewrites it.
export const entry: SemanticMigration = {
id: 'lookup-depends-on-param-computed-field-refused',
surface:
'object.fields.<field>.dependsOn[] on a lookup, master_detail or user field — the filter key the entry '
+ 'scopes the referenced object by (`param` in the { field, param } form, else the bare name or `field`), '
+ 'when it names a field of the referenced object computed on read (a formula)',
replacement:
'a stored field of the referenced object that holds the same value, written as { field: '
+ '\'this_record_field\', param: \'stored_referenced_field\' }; or drop the entry when the picker need not '
+ 'be scoped.',
reason:
'The record picker filters its candidates, and the importer scopes a lookup cell, by this key on the '
+ 'referenced object, and the engine refuses every filter on a field computed on read. Such an entry '
+ 'published clean, then every picker query it scoped was refused and every import of the column failed '
+ 'its lookup. object-field-ref-unknown now reports it as an error, on objectstack validate and at the '
+ 'runtime publish gate. No D2 conversion exists: only the author knows which stored field carries the '
+ 'value the formula computes.',
acceptanceCriteria:
'Run objectstack validate: no object-field-ref-unknown finding says a dependsOn entry names a field '
+ 'computed on read. For each entry it named, the filter key is a stored field of the referenced object, or '
+ 'the entry is gone, and the record picker lists candidates once the field it depends on has a value.',
};
Loading
Loading