Skip to content

Commit f9dcf30

Browse files
committed
fix(core,plugin-grid): the could-not-look-up sentence is given only for the filter seam's refusal of the scope
A scoped lookup answers import_reference_scope_unqueryable only when a read was refused INVALID_FIELD naming a scope field, read off the refusal's declared code and fields. Every other all-refused lookup (no read on the target, a driver fault) keeps the plain sentence. The sentence's remedy names the target field the dependsOn entry filters by. The Import Wizard joins several scope entries with the pack's own separator (grid.import.scopeSeparator). Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgWgMUXf5juNBhN6rLX
1 parent 6760d27 commit f9dcf30

21 files changed

Lines changed: 107 additions & 31 deletions

‎.changeset/36794-wizard-reference-out-of-scope.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Metadata-protocol: none
1212

1313
The Import Wizard's dry run and completion screen render the import cell error `reference_out_of_scope` (#36794) with their own text, `"Design review" was found, but not under Project "Gemini"`, built from the cell error's `scope` (each scoping column by its label, with the cell the row gave it) and translated in all eleven UI locales (`grid.import.referenceOutOfScope`, `grid.import.scopeEntry`). The Wizard keys on the code and the structured `scope`, never on the server's sentence; a cell error with no `scope` shows the server's own sentence, already in the caller's locale.
1414

15-
The importer no longer reports a scoped lookup as `reference_out_of_scope` when none of its scoped reads could run: a `dependsOn` whose `param` names a target field the engine cannot filter by (a `formula`) refuses every scoped read, so the scope was never asked. That cell keeps `reference_not_found`, with its own catalog sentence `import_reference_scope_unqueryable` in all four platform locales, which says the lookup could not be made within the scope and that the field's `dependsOn` needs another column. No unscoped probe runs for it and it carries no `scope`.
15+
The importer no longer reports a scoped lookup as `reference_out_of_scope` when the engine refused its scoped reads because of the scope: a `dependsOn` whose `param` names a target field the engine cannot filter by (a `formula`) has every scoped read refused (`INVALID_FIELD` naming that field), so the scope was never asked. That cell keeps `reference_not_found`, with its own catalog sentence `import_reference_scope_unqueryable` in all four platform locales, which says the lookup could not be made within the scope and that the `dependsOn` entry should point at a stored target field. No unscoped probe runs for it and it carries no `scope`. 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.
1616

1717
Wording: `ImportRowResultSchema.errors` and the runner's `ImportRowResult.errors` now say that a `reference_out_of_scope` element carries `scope`; the error catalog page says `scope` names the row's own scoping columns, not the parent's.
1818

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,13 @@ that caller can read and whose name is unique. Without the master (or the `depen
370370
sibling) in the row, the same cell resolves.
371371

372372
A `dependsOn` entry whose `param` names a target field the engine cannot filter by (a
373-
`formula`) cannot scope the lookup at all: every scoped read is refused, so the cell fails
374-
with `reference_not_found` and a sentence that says the lookup could not be made within the
375-
scope (`Task: "Design review" could not be looked up within Project = "Gemini": …`), never
376-
`reference_out_of_scope`. Point `param` at a stored field of the target.
373+
`formula`) cannot scope the lookup at all: the engine refuses every scoped read, so the cell
374+
fails with `reference_not_found` and a sentence that says the lookup could not be made within
375+
the scope and names the cause (`Task: "Design review" could not be looked up within Project =
376+
"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.
377380

378381
A pasted id is scoped too, so a row that means another master's detail cannot be linked
379382
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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ export interface RefMatch {
9797
*/
9898
scopeDenied?: boolean;
9999
/**
100-
* [#36794] The SCOPED lookup asked nothing: every candidate read failed, so
101-
* the scope names a target field the engine cannot filter by (a formula, or
102-
* any other field a `where` cannot name). The refusal stays
103-
* `reference_not_found` and says the lookup could not be made within the
104-
* row's scope, never that the value lives under another parent.
100+
* [#36794] The SCOPED lookup asked nothing: no candidate read answered, and
101+
* the engine's filter seam refused a read because the scope names a target
102+
* field it cannot filter by (a formula), judged off that refusal's declared
103+
* `code` and `fields`. Every other all-refused lookup is a plain miss. The
104+
* refusal stays `reference_not_found` and says the lookup could not be made
105+
* within the row's scope, never that the value lives under another parent.
105106
*/
106107
scopeUnqueryable?: boolean;
107108
}
@@ -186,8 +187,9 @@ interface ScopedBy {
186187
* A scoped read the field-predicate guard refused (`RefMatch.scopeDenied`: the
187188
* scope names a target field the caller cannot read) is never probed: its miss
188189
* says nothing about where the value lives, so it stays `reference_not_found`.
189-
* A scoped lookup none of whose reads ran (`RefMatch.scopeUnqueryable`: the scope
190-
* names a target field the engine cannot filter by) is not probed either: it
190+
* A scoped lookup none of whose reads answered because the engine's filter seam
191+
* refused the scope (`RefMatch.scopeUnqueryable`: the scope names a target field
192+
* the engine cannot filter by, such as a formula) is not probed either: it
191193
* stays `reference_not_found` with its own sentence, which says the lookup
192194
* could not be made within the row's scope.
193195
*

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ describe('[#36159] [#36794] a scoped miss whose value exists outside the row\'s
353353
const summary = await run(p, [{ name: 'INV-1', project: 'Gemini', task: 'Design review' }]);
354354
expect(summary.results.map(refusal)).toEqual([{
355355
ok: false, code: 'reference_not_found', field: 'task',
356-
error: 'task: "Design review" could not be looked up within Project = "Gemini": the lookup\'s target cannot be '
357-
+ 'filtered by that column, so the lookup field\'s dependsOn needs another one',
356+
error: 'task: "Design review" could not be looked up within Project = "Gemini": the target field this lookup\'s '
357+
+ 'dependsOn filters by cannot be filtered on, so point that dependsOn entry at a stored field',
358358
}]);
359359
expect(summary.results.map(cellErrors)).toEqual([[{ field: 'task', code: 'reference_not_found', scope: undefined }]]);
360360
// No unscoped probe ran.
@@ -363,6 +363,40 @@ describe('[#36159] [#36794] a scoped miss whose value exists outside the row\'s
363363
for (const c of taskReads) expect(c.query!.where).toHaveProperty('project');
364364
});
365365

366+
it('a scoped lookup whose every read is refused for another reason (no read on the target): the plain sentence, no cause claimed', async () => {
367+
const { p, findData } = protocol();
368+
// The caller holds no read on xm_task: every read of it is refused, naming no field.
369+
findData.mockImplementation(async (args: FindArgs) => {
370+
if (args.object === 'xm_task') {
371+
throw Object.assign(new Error('[Security] Access denied'), {
372+
code: 'PERMISSION_DENIED', status: 403, details: { object: 'xm_task' },
373+
});
374+
}
375+
return (ROWS[args.object] ?? []).filter((r) => matches(r, args.query!.where as Record<string, unknown>));
376+
});
377+
const summary = await run(p, [{ name: 'INV-1', project: 'Gemini', task: 'Design review' }]);
378+
expect(summary.results.map(refusal)).toEqual([
379+
{ ok: false, code: 'reference_not_found', field: 'task', error: 'task: no record matches "Design review"' },
380+
]);
381+
expect(summary.results.map(cellErrors)).toEqual([[{ field: 'task', code: 'reference_not_found', scope: undefined }]]);
382+
});
383+
384+
it('an INVALID_FIELD refusal naming a field outside the scope is not the scope\'s: the plain sentence', async () => {
385+
const { p, findData } = protocol();
386+
findData.mockImplementation(async (args: FindArgs) => {
387+
if (args.object === 'xm_task') {
388+
throw Object.assign(new Error("ObjectQL.find('xm_task') filters on 'name', a virtual formula field"), {
389+
code: 'INVALID_FIELD', status: 400, field: 'name', fields: ['name'],
390+
});
391+
}
392+
return (ROWS[args.object] ?? []).filter((r) => matches(r, args.query!.where as Record<string, unknown>));
393+
});
394+
const summary = await run(p, [{ name: 'INV-1', project: 'Gemini', task: 'Design review' }]);
395+
expect(summary.results.map(refusal)).toEqual([
396+
{ ok: false, code: 'reference_not_found', field: 'task', error: 'task: no record matches "Design review"' },
397+
]);
398+
});
399+
366400
it('the unscoped probe is the importing caller\'s own read, and a record that caller cannot read stays unnamed', async () => {
367401
const { p, findData } = protocol();
368402
// 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: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,21 @@ function isScopeFieldDenial(e: unknown, scope: Readonly<Record<string, unknown>>
830830
return details.fields.some((f) => typeof f === 'string' && Object.prototype.hasOwnProperty.call(scope, f));
831831
}
832832

833+
/**
834+
* [#36794] Whether a scoped lookup read was refused because its scope names a
835+
* target field the engine cannot filter by (a `formula`): the filter seam's
836+
* refusal (`code: 'INVALID_FIELD'`, the code both filter doors declare) naming
837+
* at least one scope field in its `fields`. Read off the error's declared
838+
* properties, never its message, so any other refusal of the read (no read
839+
* grant on the target, a driver fault) is not taken for this one.
840+
*/
841+
function isScopeFilterRefusal(e: unknown, scope: Readonly<Record<string, unknown>>): boolean {
842+
const err = e as { code?: unknown; fields?: unknown; details?: { fields?: unknown } } | null;
843+
if (err?.code !== 'INVALID_FIELD') return false;
844+
const fields = Array.isArray(err.fields) ? err.fields : Array.isArray(err.details?.fields) ? err.details!.fields : [];
845+
return (fields as unknown[]).some((f) => typeof f === 'string' && Object.prototype.hasOwnProperty.call(scope, f));
846+
}
847+
833848
/**
834849
* [#27465] The refusal of a match key naming a field that holds a list or a
835850
* structured value, or `undefined` when every named field can be a key.
@@ -999,10 +1014,12 @@ export function runImport(opts: RunImportOptions): Promise<ImportRunSummary> {
9991014
.filter((f) => !scope || !Object.prototype.hasOwnProperty.call(scope, f));
10001015
const lookup = async (): Promise<RefMatch> => {
10011016
let match: RefMatch = {};
1002-
// [#36794] Whether any candidate read ran to an answer. A scoped lookup
1003-
// none of whose reads did (the scope names a target field the engine
1004-
// cannot filter by, such as a formula) never asked its question.
1017+
// [#36794] Whether any candidate read ran to an answer, and whether a read
1018+
// was refused because the scope names a target field the engine cannot
1019+
// filter by (a formula). A scoped lookup none of whose reads answered, and
1020+
// at least one of whose refusals said so, never asked its question.
10051021
let asked = false;
1022+
let scopeUnfilterable = false;
10061023
for (const f of candidates) {
10071024
try {
10081025
const r = await p.findData(findArgsBase({
@@ -1023,10 +1040,13 @@ export function runImport(opts: RunImportOptions): Promise<ImportRunSummary> {
10231040
// about where the value lives: report it as such, never as a record
10241041
// that lives under another parent.
10251042
if (scope && isScopeFieldDenial(e, scope)) { match = { scopeDenied: true }; break; }
1043+
if (scope && isScopeFilterRefusal(e, scope)) scopeUnfilterable = true;
10261044
/* field absent on target object — try the next candidate */
10271045
}
10281046
}
1029-
if (scope && !asked && !match.scopeDenied) match = { scopeUnqueryable: true };
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 };
10301050
return match;
10311051
};
10321052
let match = await lookup();

‎packages/qa/dogfood/test/import-reference-out-of-scope.dogfood.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ describe('[#36794] a scoped import lookup naming another parent\'s record answer
174174
const [row] = await importAs(token.admin, [{ name: 'TS-F1', project: 'Gemini', task_by_ref: 'Design review' }]);
175175
expect(row, JSON.stringify(row)).toMatchObject({
176176
ok: false, field: 'task_by_ref', code: 'reference_not_found',
177-
error: 'Task by ref: "Design review" could not be looked up within Project = "Gemini": the lookup\'s target '
178-
+ 'cannot be filtered by that column, so the lookup field\'s dependsOn needs another one',
177+
error: 'Task by ref: "Design review" could not be looked up within Project = "Gemini": the target field this '
178+
+ 'lookup\'s dependsOn filters by cannot be filtered on, so point that dependsOn entry at a stored field',
179179
});
180180
expect(row!.errors?.[0]).not.toHaveProperty('scope');
181181
});

‎packages/spec/src/system/validation-message.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ describe('import_reference_scope_unqueryable — names the value and the scope i
327327
it('renders the English sentence', () => {
328328
const params = { value: 'Design review', scope: 'Project = "Gemini"' };
329329
expect(renderValidationMessage({ messageKey: 'import_reference_scope_unqueryable', label: 'Task', params }))
330-
.toBe('Task: "Design review" could not be looked up within Project = "Gemini": the lookup\'s target cannot be '
331-
+ 'filtered by that column, so the lookup field\'s dependsOn needs another one');
330+
.toBe('Task: "Design review" could not be looked up within Project = "Gemini": the target field this lookup\'s '
331+
+ 'dependsOn filters by cannot be filtered on, so point that dependsOn entry at a stored field');
332332
});
333333
});

0 commit comments

Comments
 (0)