From 64abfecd635f17a739dd2ce9d85afea23c6c1af2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 08:14:06 +0000 Subject: [PATCH 1/5] fix(metadata-protocol)!: a seed record that leaves a key field blank is refused at load A keyed seed record (ignore, upsert, update) whose externalId value is blank - no value, null or an empty string, in any component of a composite key or the one field of a single-field key (name by default) - keyed empty, matched no row and was inserted again on every load with nothing said (measured 2 -> 3 -> 4 rows). The load now refuses it on the key as authored, after expressions resolve and before references do: one error naming the object, record index, blank field(s) and the fix, logged once per dataset; every other record loads. A deferred reference is authored, so it is not blank and still lands. The all-empty dataset warning is replaced by the per-record refusal. Tests: new pins in the seed-loader harness files; the keyless devices that relied on a blank key are remade on the mode-less (unparsed) load; consumer fixtures that keyed records on a field they did not carry are re-keyed. Docs: the seed-data page states the rule and its keyless TestUser example gains externalId 'email'. ADR-0087 ledger entry seed-key-blank-record-refused registers the narrowing. Claude-Session: https://claude.ai/code/session_01Utp6CaysxGzF62ACvZ1x9x Co-authored-by: Claude --- .../34857-seed-blank-key-record-refused.md | 19 ++ content/docs/data-modeling/seed-data.mdx | 12 +- .../protocol.seed-external-id-refusal.test.ts | 4 +- ...ed-loader-composite-key-diagnostic.test.ts | 14 +- .../src/seed-loader-deferred-dropped.test.ts | 66 ++++-- ...seed-loader-deferred-key-reference.test.ts | 38 +++ .../src/seed-loader-empty-key-warn.test.ts | 218 +++++++++++++----- .../src/seed-loader-pointer-pair.test.ts | 22 +- packages/metadata-protocol/src/seed-loader.ts | 115 +++++++-- .../src/engine-seed-required-deferral.test.ts | 19 +- packages/runtime/src/seed-loader.test.ts | 10 +- .../18.seed-key-blank-record-refused.ts | 35 +++ 12 files changed, 453 insertions(+), 119 deletions(-) create mode 100644 .changeset/34857-seed-blank-key-record-refused.md create mode 100644 packages/spec/src/migrations/entries/semantic/18.seed-key-blank-record-refused.ts diff --git a/.changeset/34857-seed-blank-key-record-refused.md b/.changeset/34857-seed-blank-key-record-refused.md new file mode 100644 index 00000000000..169acb8501a --- /dev/null +++ b/.changeset/34857-seed-blank-key-record-refused.md @@ -0,0 +1,19 @@ +--- +'@objectstack/metadata-protocol': minor +--- + +fix(metadata-protocol)!: a seed record that leaves a key field blank is refused at load instead of being inserted again on every load + +Clause-②: no (narrowing) +Metadata-protocol: narrowed +Skills-docs: follow-up owed — skills/objectstack-data/references/seeds.md (:48 the externalId row, :68 the composite key, :93 `externalId` selection: none says a record must carry every key field or is refused at load) + + + +**BREAKING** for a seed record whose `externalId` value is blank. A seed is replayed on every single-tenant boot, every package install or upgrade and every publish, and each replay matches records to the rows earlier loads wrote by the dataset's `externalId`. A record that left a key field blank (no value, `null` or `''`): any component of a composite key such as `['team', 'project']`, or the one field of a single-field key (`name` when the dataset names none), matched no row and was written again by every `ignore` or `upsert` load, with nothing said. Measured over three loads of one such record beside a keyed one: 2, then 3, then 4 rows. An `update` load skipped it, also in silence. + +- FROM: the record was written as a new row on every load (`ignore`, `upsert`) or skipped (`update`); when every record of a dataset keyed empty, the load logged one dataset-level `warn` and still wrote each record again. +- TO: in the keyed modes (`ignore`, `upsert`, `update`) the load refuses the record before anything of it is written: the load result carries one error for it naming the object, the record index, the blank field(s) and the fix, the boot log says it once per dataset at `error`, and every other record and dataset loads. A dry run (`validate`) reports the same error. A dataset whose every record keys empty is the same refusal for each record; the dataset-level `warn` is gone, since it would report the same records twice. +- The fix for an author: give the record a value for the blank key field, or key the dataset on fields every record carries: a field the object declares, a list of fields when no single field names a row, or `'id'` when the records carry their own ids. + +**Not moved.** The check reads the key as authored, after the record's expressions resolve and before any reference resolves. A reference the load defers or cannot resolve yet (a person who has not signed up) is authored, so it is not blank and its row lands and holds one row across loads, as before. A whitespace-only value is a value, as before. Rows earlier loads duplicated are data and stay; remove the extra copies yourself if they matter. A request built without the parse's defaults (no `mode` on the dataset, no `defaultMode` on the config) is not keyed and is unchanged. diff --git a/content/docs/data-modeling/seed-data.mdx b/content/docs/data-modeling/seed-data.mdx index ec2b0053f1c..e0df69b57da 100644 --- a/content/docs/data-modeling/seed-data.mdx +++ b/content/docs/data-modeling/seed-data.mdx @@ -76,6 +76,13 @@ customer has since edited. | `update` | Update only, skip if not found | Migration patches on existing rows | Every mode matches on `externalId`, so a replay finds the row an earlier load wrote. +Every record carries a value for each `externalId` field (`name` when the dataset +names none). A record that leaves one blank (no value, `null` or `''`) could match no +row and would be inserted again on every replay, so the load refuses it: nothing of +it is written, the load reports an error naming the object, the record and the blank +field, and the dataset's other records load. The check reads the key as written in the +seed, so a reference the load cannot resolve yet (a person who has not signed up) is +not blank. The unkeyed modes `insert` and `replace` are retired: see [Moving off `insert` and `replace`](#moving-off-insert-and-replace). @@ -311,6 +318,7 @@ defineSeed(Account, { // Automated test fixtures — CI/CD only defineSeed(TestUser, { + externalId: 'email', // the records carry no `name`, the default key env: ['test'], records: [ { email: 'ci-admin@example.com', role: 'admin' }, @@ -608,7 +616,9 @@ A join (junction) table linking two objects many-to-many has **no single-field natural key** — the *pair* of foreign keys is what makes a row unique. Pass a **list** of field names as the `externalId` so the seed runner can match existing rows on the composite key and stay idempotent across replays. The foreign keys are -compared by their *resolved* record ids, which are stable between boots. +compared by their *resolved* record ids, which are stable between boots. Every record +carries every listed field: a record with one of them blank is refused at load, like +any record with a blank key (see [Import Modes](#import-modes)). ```typescript // A team can staff many projects; a project can have many teams. diff --git a/packages/metadata-protocol/src/protocol.seed-external-id-refusal.test.ts b/packages/metadata-protocol/src/protocol.seed-external-id-refusal.test.ts index 778797ca31d..11a06fc32db 100644 --- a/packages/metadata-protocol/src/protocol.seed-external-id-refusal.test.ts +++ b/packages/metadata-protocol/src/protocol.seed-external-id-refusal.test.ts @@ -188,7 +188,9 @@ const seed = (target: string, externalId: string | string[] | undefined, mode = object: target, mode, ...(externalId !== undefined ? { externalId } : {}), - records: [{ name: 'G1', sku: 'g', organization_id: 'org_seedkey' }], + // A dataset keyed on `id` carries the id on its record: a keyed load refuses + // a record that leaves a key field blank (#34857). + records: [{ name: 'G1', sku: 'g', organization_id: 'org_seedkey', ...(externalId === 'id' ? { id: 'seedkey_g1' } : {}) }], }); /** Plant a seed draft as a draft stored before the rule sits at rest. */ diff --git a/packages/metadata-protocol/src/seed-loader-composite-key-diagnostic.test.ts b/packages/metadata-protocol/src/seed-loader-composite-key-diagnostic.test.ts index d897db91eb7..42e31375f13 100644 --- a/packages/metadata-protocol/src/seed-loader-composite-key-diagnostic.test.ts +++ b/packages/metadata-protocol/src/seed-loader-composite-key-diagnostic.test.ts @@ -345,7 +345,7 @@ describe('[#16488] negative control: the U+0000 joiner still separates map keys' expect(nulCount('a')).toBe(0); }); - it("the ruling's own pair — ('a','b') and ('a\\0b','') — still do not collide", async () => { + it("the ruling's own pair — ('a','b') and ('a\\0b','') — still do not collide: the blank-component record is refused, never matched", async () => { const objects = { demo_pair: { name: 'demo_pair', fields: { a: { type: 'text' }, b: { type: 'text' } } } }; const seeds = [{ object: 'demo_pair', @@ -362,10 +362,14 @@ describe('[#16488] negative control: the U+0000 joiner still separates map keys' const result = await new SeedLoaderService(engine, createMetadata(objects), createLogger() as never) .load({ seeds, config: CONFIG } as never); - expect(result.success).toBe(true); - // Two rows, not one: the second never matched the first. - expect(store.demo_pair).toHaveLength(2); - expect(store.demo_pair.map((r: any) => r.a).sort()).toEqual([`a${NUL}b`, 'a'].sort()); + // [#34857] The second record leaves `b` blank, so a keyed load refuses it + // before it is written; it is reported by index, never matched to (or + // swallowed by) the first row, which lands on its own. + expect(result.success).toBe(false); + expect(store.demo_pair).toHaveLength(1); + expect(store.demo_pair[0].a).toBe('a'); + expect(result.errors).toHaveLength(1); + expect(result.errors[0]).toMatchObject({ sourceObject: 'demo_pair', field: 'b', recordIndex: 1 }); }); it('a pair that WOULD collide under a visible `+` joiner still dedupes as two rows on replay', async () => { diff --git a/packages/metadata-protocol/src/seed-loader-deferred-dropped.test.ts b/packages/metadata-protocol/src/seed-loader-deferred-dropped.test.ts index 952f4b887a4..8799aff2ac8 100644 --- a/packages/metadata-protocol/src/seed-loader-deferred-dropped.test.ts +++ b/packages/metadata-protocol/src/seed-loader-deferred-dropped.test.ts @@ -129,12 +129,21 @@ const CONFIG = { transaction: false, } as any; -/** Composite-keyed department seed; `region` decides whether its key registers. */ -const compositeSeeds = (region: string) => [ +/** + * Composite-keyed department seed; `region` decides whether its key registers. + * + * A KEYED load refuses a record that leaves a key component blank, before + * anything of it is written (#34857), so the keyless device — a WRITTEN row + * whose natural key is `''` — is a department dataset that names no mode, read + * by a load whose config names no default either ({@link KEYLESS_CONFIG}): a + * request built without the parse's defaults, the one load that still writes + * such a row. The worker dataset stays keyed (`ignore`). + */ +const compositeSeeds = (region: string, mode: 'ignore' | null = 'ignore') => [ { object: 'drop_department', externalId: ['name', 'region'], - mode: 'ignore', + ...(mode === null ? {} : { mode }), env: ['prod', 'dev', 'test'], records: [{ name: 'Engineering', region, head_id: 'Alice' }], }, @@ -147,6 +156,12 @@ const compositeSeeds = (region: string) => [ }, ] as any[]; +/** The keyless device's seeds: `region` blank, the department dataset mode-less. */ +const keylessSeeds = () => compositeSeeds('', null); + +/** A load config with no default mode, so a dataset naming none is not keyed. */ +const KEYLESS_CONFIG = { ...CONFIG, defaultMode: undefined } as any; + const deferredDropLines = (logger: ReturnType) => logger.error.mock.calls.filter((c: unknown[]) => String(c[0]).includes('Deferred reference DROPPED')); @@ -171,8 +186,8 @@ describe('pass 2 heals a row whose natural key evaluated empty (#5127 → #11674 const logger = createLogger(); const result = await new SeedLoaderService(engine, createMetadata(), logger).load({ - seeds: compositeSeeds(''), - config: CONFIG, + seeds: keylessSeeds(), + config: KEYLESS_CONFIG, }); // The row is there AND carries its association. @@ -200,18 +215,35 @@ describe('pass 2 heals a row whose natural key evaluated empty (#5127 → #11674 const logger = createLogger(); await new SeedLoaderService(engine, createMetadata(), logger).load({ + seeds: keylessSeeds(), + config: KEYLESS_CONFIG, + }); + + expect(logger.error).not.toHaveBeenCalled(); + expect(logger.warn).not.toHaveBeenCalled(); + }); + + /** + * [#34857] Why the device above is mode-less: the same department record + * in a KEYED dataset is refused at load for its blank `region`, before + * anything of it is written or deferred — no row, so no back-fill to heal + * and no pass-2 drop to report. + */ + it('a KEYED dataset refuses the blank-component record before it writes or defers anything', async () => { + const { engine, store } = createFaithfulEngine(); + const logger = createLogger(); + + const result = await new SeedLoaderService(engine, createMetadata(), logger).load({ seeds: compositeSeeds(''), config: CONFIG, }); - expect(logger.error).not.toHaveBeenCalled(); - // [#34613] The dataset is keyed now (the unkeyed `insert` it ran in is - // retired), so the one `warn` is #28952's notice that every record keys - // empty — a fact about the declaration. Nothing at warn is about the - // deferral the load healed. - const warned = logger.warn.mock.calls.map((c: unknown[]) => String(c[0])); - expect(warned).toHaveLength(1); - expect(warned[0]).toMatch(/keys every record on externalId 'name\+region', and no record carries a value for it/); + expect(store.drop_department ?? []).toHaveLength(0); + const deptResult = result.results.find((r: { object: string }) => r.object === 'drop_department')!; + expect(deptResult).toMatchObject({ inserted: 0, errored: 1, referencesDeferred: 0 }); + expect(deptResult.errors).toHaveLength(1); + expect(deptResult.errors[0]).toMatchObject({ field: 'region', recordIndex: 0 }); + expect(deferredDropLines(logger)).toHaveLength(0); }); /** @@ -226,8 +258,8 @@ describe('pass 2 heals a row whose natural key evaluated empty (#5127 → #11674 const { engine } = createFaithfulEngine(); const result = await new SeedLoaderService(engine, createMetadata(), createLogger()).load({ - seeds: compositeSeeds(''), - config: CONFIG, + seeds: keylessSeeds(), + config: KEYLESS_CONFIG, }); const deptResult = result.results.find((r: { object: string }) => r.object === 'drop_department')!; @@ -400,8 +432,8 @@ describe('pass 2 finds no id because a KEYLESS record failed in pass 1 (#11674)' const { engine, store, logger } = loadWithFailingKeylessDepartment(); const result = await new SeedLoaderService(engine, createMetadata(), logger).load({ - seeds: compositeSeeds(''), // region '' → externalIdKey '' → no natural key - config: CONFIG, + seeds: keylessSeeds(), // region '' → externalIdKey '' → no natural key + config: KEYLESS_CONFIG, }); // The row really is absent — nothing to back-fill onto. diff --git a/packages/metadata-protocol/src/seed-loader-deferred-key-reference.test.ts b/packages/metadata-protocol/src/seed-loader-deferred-key-reference.test.ts index 512ee3cc4b1..21c2bd5f49b 100644 --- a/packages/metadata-protocol/src/seed-loader-deferred-key-reference.test.ts +++ b/packages/metadata-protocol/src/seed-loader-deferred-key-reference.test.ts @@ -373,3 +373,41 @@ describe('seed: a row whose key reference was empty at landing stays deleted (#3 expect(store.dkr_task[0].assignee ?? null).toBeNull(); }); }); + +describe('seed: a key reference that resolves empty is not a blank key (#34857)', () => { + /** + * The blank-key refusal reads the key as AUTHORED, before any reference + * resolves. A deferred key reference is authored (`'Alice'`) and empty only + * after resolution, so it is never refused: the row lands, holds one row + * across loads, and the #34856 delete record above keeps working. + */ + const blankKeyRefusals = (result: any): any[] => + result.errors.filter((e: any) => e.message.includes('was NOT loaded: it is keyed on externalId')); + + for (const mode of ['ignore', 'upsert'] as const) { + it(`CONTROL ${mode}: the deferred-key row lands and is not refused, three loads one row`, async () => { + const { engine, store } = createEngine(); + const seeds = [taskSeed(mode, [{ name: 'Onboard', assignee: 'Alice', notes: 'first week' }])]; + + for (let boot = 0; boot < 3; boot++) { + const result = await load(engine, seeds); + expect(blankKeyRefusals(result)).toEqual([]); + expect(store.dkr_task).toHaveLength(1); + } + expect(store.dkr_task[0].assignee ?? null).toBeNull(); + }); + } + + it('CONTROL: beside it, a record of the same dataset whose key reference is authored blank is refused', async () => { + const { engine, store } = createEngine(); + const result = await load(engine, [taskSeed('ignore', [ + { name: 'Onboard', assignee: 'Alice' }, + { name: 'Review', assignee: '' }, + ])]); + + const refused = blankKeyRefusals(result); + expect(refused).toHaveLength(1); + expect(refused[0]).toMatchObject({ sourceObject: 'dkr_task', field: 'assignee', recordIndex: 1 }); + expect(store.dkr_task.map((r) => r.name)).toEqual(['Onboard']); + }); +}); diff --git a/packages/metadata-protocol/src/seed-loader-empty-key-warn.test.ts b/packages/metadata-protocol/src/seed-loader-empty-key-warn.test.ts index c2450c57f29..931fb748237 100644 --- a/packages/metadata-protocol/src/seed-loader-empty-key-warn.test.ts +++ b/packages/metadata-protocol/src/seed-loader-empty-key-warn.test.ts @@ -6,16 +6,22 @@ import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts' import { assertEngineDeleteDispatch, assertEngineUpdateDispatch, assertEngineFindOnePredicate } from '@objectstack/metadata-core'; /** - * [#28952] A keyed dataset whose every record keys empty. + * A keyed seed record that leaves a key field blank — no value, null or an + * empty string, in any component of a composite `externalId` or in the one + * field of a single-field key (`name` when the dataset names none) — keys + * `''`, so it can match no row a load wrote before. Measured before the + * refusal, three loads of one such record among keyed siblings: 2 -> 3 -> 4 + * rows, nothing said (#34857 composite, #35336 single-field). * - * The save door and the publish promotion refuse a seed whose `externalId` - * names no field of its object (`protocol.seed-external-id-refusal.test.ts`). - * The boot loader never refuses: a stored seed must not fail a boot. What it - * owes instead is one `warn` per dataset when no record carries a value for - * the key, because such a load can match no existing row. Its writes are - * unchanged, and that is pinned here too: replayed, such a dataset inserts - * every record again (`upsert`), which is the duplication the doors now stop - * at authoring. + * The keyed modes now REFUSE such a record at load, on the key as authored — + * after its expressions resolve, before any reference does: it is not + * written, the load result carries one error naming the object, the record, + * the blank field(s) and the fix, and every other record loads as before. A + * dataset whose every record keys empty (#28952: `externalId` names a field no + * record carries) is the same refusal for each record; its dataset-level + * notice is gone, since it would report the same records twice. The save door + * and the publish promotion still refuse a seed whose `externalId` names no + * field of its object (`protocol.seed-external-id-refusal.test.ts`). * * Uses the faithful engine of `seed-loader-composite-external-id.test.ts` * (filters `where`, mints ids), kept local. @@ -106,75 +112,173 @@ const CONFIG = { const dataset = (externalId: string | string[], mode = 'upsert', records: Record[] = [{ name: 'G1', code: 'g' }]) => ({ object: 'demo_other', externalId, mode, env: ['prod', 'dev', 'test'], records }); -/** The loader's empty-key warnings, by their message. */ -const emptyKeyWarnings = (logger: ReturnType) => - logger.warn.mock.calls.map((c) => String(c[0])).filter((m) => m.includes('no record carries a value for it')); +/** The loader's blank-key refusals in a load result, by their message. */ +const blankKeyRefusals = (result: any): any[] => + result.errors.filter((e: any) => e.message.includes('was NOT loaded: it is keyed on externalId')); -describe('[#28952] the boot loader — a keyed dataset whose every record keys empty', () => { - it('warns once per dataset, naming the object and the key, and never refuses; a replay inserts every record again', async () => { - const { engine, store } = createFaithfulEngine(); - const metadata = createMetadata(); - const seeds = [dataset('no_such_field')] as any[]; +/** The blank-key refusal lines the loader logged. */ +const blankKeyLines = (logger: ReturnType) => + logger.error.mock.calls.map((c) => String(c[0])).filter((m) => m.includes('was NOT loaded: it is keyed on externalId')); +/** Three loads of one stored seed, each by a fresh loader over the same store — three boots. */ +async function threeLoads(seeds: any[]) { + const { engine, store } = createFaithfulEngine(); + const counts: number[] = []; + const results: any[] = []; + const loggers: Array> = []; + for (let boot = 0; boot < 3; boot++) { const logger = createLogger(); - const first = await new SeedLoaderService(engine, metadata, logger).load({ seeds, config: CONFIG }); - expect(first.success).toBe(true); - expect(first.results[0]).toMatchObject({ object: 'demo_other', inserted: 1 }); - const warned = emptyKeyWarnings(logger); - expect(warned).toHaveLength(1); - expect(warned[0]).toContain("Seed dataset for 'demo_other' keys every record on externalId 'no_such_field'"); - - // The replay a boot makes of the same stored seed: unchanged writes, so - // the row is inserted again. The doors refuse such a seed at authoring. - const replayLogger = createLogger(); - const second = await new SeedLoaderService(engine, metadata, replayLogger).load({ seeds, config: CONFIG }); - expect(second.success).toBe(true); - expect(second.results[0]).toMatchObject({ inserted: 1, updated: 0 }); - expect(store.demo_other).toHaveLength(2); - expect(emptyKeyWarnings(replayLogger)).toHaveLength(1); + results.push(await new SeedLoaderService(engine, createMetadata(), logger).load({ seeds, config: CONFIG })); + counts.push((store.demo_other ?? []).length); + loggers.push(logger); + } + return { store, counts, results, loggers }; +} + +describe('[#34857, #35336] the boot loader refuses a keyed record that leaves a key field blank', () => { + for (const [label, blank] of [['empty string', ''], ['null', null], ['no value', undefined]] as const) { + it(`composite key, one component ${label}: the record is not written, its siblings converge`, async () => { + const blankRecord: Record = { name: 'B' }; + if (blank !== undefined) blankRecord.code = blank; + const { store, counts, results, loggers } = await threeLoads([ + dataset(['name', 'code'], 'upsert', [{ name: 'A', code: 'a' }, blankRecord, { name: 'C', code: 'c' }]), + ]); + + expect(counts).toEqual([2, 2, 2]); + expect(store.demo_other.map((r) => r.name).sort()).toEqual(['A', 'C']); + for (const result of results) { + expect(result.success).toBe(false); + expect(result.results[0]).toMatchObject({ object: 'demo_other', errored: 1, total: 3 }); + const refused = blankKeyRefusals(result); + expect(refused).toHaveLength(1); + expect(refused[0]).toMatchObject({ sourceObject: 'demo_other', field: 'code', recordIndex: 1 }); + expect(refused[0].message).toContain( + "Seed record #1 of 'demo_other' was NOT loaded: it is keyed on externalId 'name+code' and leaves 'code' blank", + ); + expect(refused[0].message).toContain("Give the record a value for 'code'"); + } + // Logged once per load, at `error`: the record is dropped. + for (const logger of loggers) expect(blankKeyLines(logger)).toHaveLength(1); + }); + } + + it('single-field key: a record with no value for it is refused; its keyed sibling converges', async () => { + const { counts, results } = await threeLoads([dataset('code', 'upsert', [{ name: 'A', code: 'a' }, { name: 'B' }])]); + + expect(counts).toEqual([1, 1, 1]); + for (const result of results) { + const refused = blankKeyRefusals(result); + expect(refused).toHaveLength(1); + expect(refused[0]).toMatchObject({ sourceObject: 'demo_other', field: 'code', recordIndex: 1 }); + expect(refused[0].message).toContain("keyed on externalId 'code' and leaves 'code' blank"); + } + }); + + it('the default key (`name`, no externalId declared): a record with no name is refused, and the message says the key is the default', async () => { + const seed = { object: 'demo_other', mode: 'ignore', env: ['prod', 'dev', 'test'], records: [{ name: 'A', code: 'a' }, { code: 'b' }] }; + const { counts, results } = await threeLoads([seed]); + + expect(counts).toEqual([1, 1, 1]); + const refused = blankKeyRefusals(results[0]); + expect(refused).toHaveLength(1); + expect(refused[0]).toMatchObject({ field: 'name', recordIndex: 1 }); + expect(refused[0].message).toContain("keyed on externalId 'name' (the default key when a dataset names none) and leaves 'name' blank"); + }); + + it('an expression that evaluates empty in a key field is refused the same way (it is read after expressions resolve)', async () => { + // `os.user.id` is null at seed time when no identity is supplied. + const { counts, results } = await threeLoads([ + dataset(['name', 'code'], 'upsert', [{ name: 'A', code: 'a' }, { name: 'B', code: { dialect: 'cel', source: 'os.user.id' } }]), + ]); + + expect(counts).toEqual([1, 1, 1]); + const refused = blankKeyRefusals(results[0]); + expect(refused).toHaveLength(1); + expect(refused[0]).toMatchObject({ field: 'code', recordIndex: 1 }); + }); + + it('an `update` dataset reports the record instead of skipping it in silence', async () => { + const { results } = await threeLoads([dataset('code', 'update', [{ name: 'B' }])]); + const refused = blankKeyRefusals(results[0]); + expect(refused).toHaveLength(1); + expect(refused[0].message).toContain('so an update load can never find the row it names'); + expect(results[0].results[0]).toMatchObject({ errored: 1, inserted: 0, updated: 0 }); }); - it('a composite key with a member no record carries warns the same way', async () => { + it('a dry run reports the refusal and logs nothing', async () => { const { engine } = createFaithfulEngine(); const logger = createLogger(); - await new SeedLoaderService(engine, createMetadata(), logger).load({ - seeds: [dataset(['code', 'no_such_field'], 'ignore')] as any[], config: CONFIG, + const result = await new SeedLoaderService(engine, createMetadata(), logger).load({ + seeds: [dataset('code', 'upsert', [{ name: 'B' }])] as any[], config: { ...CONFIG, dryRun: true }, }); - const warned = emptyKeyWarnings(logger); - expect(warned).toHaveLength(1); - expect(warned[0]).toContain("externalId 'code+no_such_field'"); + expect(blankKeyRefusals(result)).toHaveLength(1); + expect(blankKeyLines(logger)).toEqual([]); }); - it('control: a declared key converges on replay and warns nothing', async () => { - const { engine, store } = createFaithfulEngine(); - const metadata = createMetadata(); - const seeds = [dataset('name')] as any[]; + it('CONTROL: a fully keyed dataset converges on replay, refuses nothing and says nothing', async () => { + const { counts, results, loggers } = await threeLoads([ + dataset(['name', 'code'], 'upsert', [{ name: 'A', code: 'a' }, { name: 'B', code: 'b' }]), + ]); - const logger = createLogger(); - const first = await new SeedLoaderService(engine, metadata, logger).load({ seeds, config: CONFIG }); - expect(first.results[0]).toMatchObject({ inserted: 1 }); - const second = await new SeedLoaderService(engine, metadata, logger).load({ seeds, config: CONFIG }); - expect(second.results[0]).toMatchObject({ inserted: 0, updated: 0 }); - expect(store.demo_other).toHaveLength(1); - expect(emptyKeyWarnings(logger)).toEqual([]); + expect(counts).toEqual([2, 2, 2]); + for (const result of results) { + expect(result.success).toBe(true); + expect(result.errors).toEqual([]); + } + for (const logger of loggers) { + expect(logger.error).not.toHaveBeenCalled(); + expect(logger.warn).not.toHaveBeenCalled(); + } + }); + + it('CONTROL: a whitespace-only key value is a value, as before (no trim)', async () => { + const { counts, results } = await threeLoads([dataset('code', 'upsert', [{ name: 'A', code: ' ' }])]); + expect(counts).toEqual([1, 1, 1]); + expect(blankKeyRefusals(results[0])).toEqual([]); + }); +}); + +describe('[#28952] the boot loader — a keyed dataset whose every record keys empty', () => { + it('refuses every record, one error each in the result, one line logged per dataset, and never writes', async () => { + const { store, counts, results, loggers } = await threeLoads([ + dataset('no_such_field', 'upsert', [{ name: 'G1', code: 'g' }, { name: 'G2', code: 'h' }]), + ]); + + expect(counts).toEqual([0, 0, 0]); + expect(store.demo_other).toBeUndefined(); + for (const result of results) { + expect(result.results[0]).toMatchObject({ object: 'demo_other', inserted: 0, errored: 2, total: 2 }); + const refused = blankKeyRefusals(result); + expect(refused.map((e) => e.recordIndex)).toEqual([0, 1]); + // The fix names the dataset-level remedy too: key on a field every record carries. + expect(refused[0].message).toContain("or key the dataset on fields every record carries: a field the object declares"); + } + for (const logger of loggers) { + expect(blankKeyLines(logger)).toHaveLength(1); + // No second, dataset-level report of the same records. + expect(logger.warn).not.toHaveBeenCalled(); + } }); - it('control: a retired `insert` dataset is refused before any key is read, so it is not warned about (#34613)', async () => { + it('a composite key with a member no record carries is refused the same way', async () => { const { engine } = createFaithfulEngine(); const logger = createLogger(); const result = await new SeedLoaderService(engine, createMetadata(), logger).load({ - seeds: [dataset('no_such_field', 'insert')] as any[], config: CONFIG, + seeds: [dataset(['code', 'no_such_field'], 'ignore')] as any[], config: CONFIG, }); - expect(result.results[0]).toMatchObject({ inserted: 0, errored: 1 }); - expect(emptyKeyWarnings(logger)).toEqual([]); + const refused = blankKeyRefusals(result); + expect(refused).toHaveLength(1); + expect(refused[0]).toMatchObject({ field: 'no_such_field', recordIndex: 0 }); + expect(refused[0].message).toContain("keyed on externalId 'code+no_such_field' and leaves 'no_such_field' blank"); }); - it('control: a dataset where some record carries the key is not warned about', async () => { + it('control: a retired `insert` dataset is refused before any key is read, so it carries no blank-key refusal (#34613)', async () => { const { engine } = createFaithfulEngine(); const logger = createLogger(); - await new SeedLoaderService(engine, createMetadata(), logger).load({ - seeds: [dataset('code', 'upsert', [{ name: 'A', code: 'a' }, { name: 'B' }])] as any[], config: CONFIG, + const result = await new SeedLoaderService(engine, createMetadata(), logger).load({ + seeds: [dataset('no_such_field', 'insert')] as any[], config: CONFIG, }); - expect(emptyKeyWarnings(logger)).toEqual([]); + expect(result.results[0]).toMatchObject({ inserted: 0, errored: 1 }); + expect(blankKeyRefusals(result)).toEqual([]); }); }); diff --git a/packages/metadata-protocol/src/seed-loader-pointer-pair.test.ts b/packages/metadata-protocol/src/seed-loader-pointer-pair.test.ts index d87f569d140..31e5ea8769f 100644 --- a/packages/metadata-protocol/src/seed-loader-pointer-pair.test.ts +++ b/packages/metadata-protocol/src/seed-loader-pointer-pair.test.ts @@ -522,10 +522,22 @@ const ADOPTER_SCHEMAS: Record = { /** A dataset for an object with no natural key of its own — every adopted * object here is engine/append-only owned. The keyless `insert` mode such * rows were once authored with is retired (#34613), so the dataset keys on - * `id`; these rows carry none, so each one is written as a new row. */ + * `id`, and each record carries its own: a keyed load refuses a record that + * leaves a key field blank (#34857). */ function insertSeed(object: string, records: Array>) { - return { object, externalId: 'id', mode: 'ignore', env: ['prod', 'dev', 'test'], records }; + return { + object, externalId: 'id', mode: 'ignore', env: ['prod', 'dev', 'test'], + records: records.map((record, i) => ({ id: `${object}_seed_${i + 1}`, ...record })), + }; +} + +/** [#34857] A dataset with no natural key at all: no `mode`, read by a load + * whose config names no default either — a request built without the parse's + * defaults, the one load that still writes a row whose key is `''`. */ +function keylessSeed(object: string, records: Array>) { + return { object, externalId: 'id', env: ['prod', 'dev', 'test'], records }; } +const KEYLESS_CONFIG = { ...CONFIG, defaultMode: undefined } as any; describe('pointer-pair adoption per object (#11386)', () => { describe('sys_audit_log — object_name / record_id', () => { @@ -583,12 +595,12 @@ describe('pointer-pair adoption per object (#11386)', () => { // can save this — and pass 2 now can, with no externalId declared. const result = await service.load({ seeds: [ - insertSeed('sys_audit_log', [ + keylessSeed('sys_audit_log', [ { action: 'read', object_name: 'crm_lead', record_id: 'Lisa Thompson' }, ]), LEAD_SEED, ] as any, - config: CONFIG, + config: KEYLESS_CONFIG, }); expect(result.success).toBe(true); @@ -919,7 +931,7 @@ describe('required-deferral early signal (#11674)', () => { ).length; } - it('FIRES when a keyless required id half defers — before the row is written, naming the fix', async () => { + it('FIRES when a required id half defers — before the row is written, naming the fix', async () => { const { service, logger, engine, store } = newService(ADOPTER_SCHEMAS); const result = await service.load({ diff --git a/packages/metadata-protocol/src/seed-loader.ts b/packages/metadata-protocol/src/seed-loader.ts index a941431498b..b10e9f2e8bb 100644 --- a/packages/metadata-protocol/src/seed-loader.ts +++ b/packages/metadata-protocol/src/seed-loader.ts @@ -453,12 +453,59 @@ function seedLandedKey(record: Record, externalId: string | str const pairs: Array<[string, string]> = []; for (const field of fields) { const value = record[field]; - if (value === undefined || value === null || value === '') return ''; + if (isBlankSeedKeyValue(value)) return ''; pairs.push([field, String(value)]); } return JSON.stringify(pairs); } +/** + * [#34857] Whether a seed record's value for one `externalId` field leaves + * that key field blank: no value, `null` or `''`. The one blank rule + * {@link seedLandedKey} and {@link SeedLoaderService.externalIdKey} key `''` + * by, and the keyed modes refuse a record by. A whitespace-only value is a + * value here (no trim). + */ +function isBlankSeedKeyValue(value: unknown): boolean { + return value === undefined || value === null || value === ''; +} + +/** + * [#34857, #35336] The refusal of a keyed seed record that leaves a key field + * blank — reported in the load result, the record not written. It names the + * object, the record, the blank field(s) and the fix; the fix covers both + * shapes it arises from: one record missing a value its siblings carry, and a + * dataset whose `externalId` names a field no record carries. + */ +function blankSeedKeyRefusal( + objectName: string, + recordIndex: number, + externalId: string | string[], + defaultKey: boolean, + blankFields: readonly string[], + mode: string | undefined, +): ReferenceResolutionError { + const fields = Array.isArray(externalId) ? externalId : [externalId]; + const keyLabel = `externalId '${fields.join('+')}'${defaultKey ? ' (the default key when a dataset names none)' : ''}`; + const blank = blankFields.map((field) => `'${field}'`).join(', '); + const consequence = mode === 'update' + ? 'so an update load can never find the row it names' + : 'so no load can ever match it to a row it wrote: written, it would be inserted again on every load'; + return { + sourceObject: objectName, + field: blankFields.join(', '), + targetObject: objectName, + targetField: '(externalId)', + attemptedValue: null, + recordIndex, + message: + `Seed record #${recordIndex} of '${objectName}' was NOT loaded: it is keyed on ${keyLabel} and leaves ` + + `${blank} blank (no value, null or an empty string), ${consequence}. Give the record a value for ` + + `${blank}, or key the dataset on fields every record carries: a field the object declares, a list of ` + + `fields when no single field names a row, or 'id' when the records carry their own ids.`, + }; +} + /** * [#34800] The id a seed row lands with when a reference in its `externalId` * is still empty on the load that inserts it — a person not signed up yet, @@ -1802,22 +1849,11 @@ export class SeedLoaderService implements ISeedLoaderService { } // [#28952] A keyed dataset whose every record keys EMPTY — its // `externalId` names a field no record carries, most often a field the - // object does not have — can never match a row: each record is written as - // new (`upsert`, `ignore`) or skipped (`update`) on every load. The save - // door and the publish promotion refuse such a seed; this load never - // refuses (a boot must not fail on a stored seed), so it says so once per - // dataset, at `warn`, and loads exactly as before. - if (keyedMode && dataset.records.length > 0 - && dataset.records.every((record) => this.externalIdKey(record as Record, externalId) === '')) { - this.logger.warn( - `[SeedLoader] Seed dataset for '${objectName}' keys every record on externalId ` + - `'${this.externalIdLabel(externalId)}', and no record carries a value for it, so this ${mode} load can ` + - `match no existing row: ${mode === 'update' ? 'every record is skipped' : 'every record is written as a new row, on every load'}. ` + - `Set externalId to a field the object declares and each record carries, a list of fields when no ` + - `single field names a row, or 'id' when the records carry their own ids.`, - { object: objectName, externalId: this.externalIdLabel(externalId), mode, records: dataset.records.length }, - ); - } + // object does not have — can never match a row. Each such record is + // refused in the record loop below with the fix for both shapes (give the + // record the value, or key the dataset on fields every record carries), the + // way any record with a blank key field is (#34857); a dataset-level + // notice on top would report the same records twice. // [#21665] Per-organization row identity. On a per-organization replay, // decide which id each row authored with an `id` holds in THIS @@ -2129,6 +2165,8 @@ export class SeedLoaderService implements ISeedLoaderService { this.unownedOrganizationCount !== undefined && seedRowNeedsOrganization(objectDefinition); let unownedRefusalLogged = false; + /** [#34857] The blank-key refusal is logged once per dataset (every refused record is still reported). */ + let blankKeyRefusalLogged = false; // Pin a single `now()` snapshot for the entire dataset so multi-pass // loads see one logical clock — the M9 determinism guarantee for seeds. @@ -2289,10 +2327,42 @@ export class SeedLoaderService implements ISeedLoaderService { authoredIdByRecordIndex.set(i, authoredId); } + // [#34857, #35336] A keyed record that leaves a key field blank — an + // empty string, null or no value; any component of a composite key, or + // the one field of a single-field key (`name` when the dataset names + // none) — keys `''`, so it matches no row this load or any earlier one + // wrote: it was inserted again on every load (never found, on `update`), + // and nothing said so. It is REFUSED here, on the key as authored: after + // its expressions resolved and its organization was stamped, BEFORE any + // reference resolves. A reference deferred to pass 2 still holds its + // authored value at this point, so it is never caught here. The blank + // rule is {@link seedLandedKey}'s and `externalIdKey`'s (no trim). + if (keyedMode) { + const blankKeyFields = [...keyFields].filter((field) => isBlankSeedKeyValue(record[field])); + if (blankKeyFields.length > 0) { + errored++; + const error = blankSeedKeyRefusal(objectName, i, externalId, dataset.externalId === undefined, blankKeyFields, mode); + errors.push(error); + allErrors.push(error); + // `error` (#4632): the record is dropped. Said once per dataset — the + // fix is the same for every such record — and every refused record + // is still reported in the result. A dry run reports it like any + // other refusal it finds. + if (!config.dryRun && !blankKeyRefusalLogged) { + blankKeyRefusalLogged = true; + this.logger.error(`[SeedLoader] ${error.message}`, undefined, { + object: objectName, recordIndex: i, fields: blankKeyFields, + }); + } + continue; + } + } + // [#34800] The key as AUTHORED, before any of its references resolves: // the identity of a row that lands while one of them is still empty. - // `''` when the dataset keys on no reference or the record leaves a key - // field blank as written; such a record matches by natural key alone. + // `''` when the dataset keys on no reference, or — outside the keyed + // modes, which refuse such a record above — when the record leaves a + // key field blank as written; such a record matches by natural key alone. const authoredKey = existingRowsById ? seedLandedKey(record, externalId) : ''; const authoredKeyValues = authoredKey === '' ? undefined @@ -5374,15 +5444,16 @@ export class SeedLoaderService implements ISeedLoaderService { * two keys match on replay and the row dedupes (framework#3434). * * Returns '' when ANY component is absent — a partial key is not a usable - * uniqueness key, so callers fall back to inserting (this mirrors the - * single-field miss, which also yields ''). + * uniqueness key (this mirrors the single-field miss, which also yields + * ''). A keyed load refuses such a record before it is written (#34857); + * only a load with no keyed mode falls back to inserting it. */ private externalIdKey(record: Record, externalId: string | string[]): string { if (Array.isArray(externalId)) { const parts: string[] = []; for (const field of externalId) { const value = record[field]; - if (value === undefined || value === null || value === '') return ''; + if (isBlankSeedKeyValue(value)) return ''; parts.push(String(value)); } return parts.join('\u0000'); diff --git a/packages/objectql/src/engine-seed-required-deferral.test.ts b/packages/objectql/src/engine-seed-required-deferral.test.ts index f15c83cfa8c..3602a777d86 100644 --- a/packages/objectql/src/engine-seed-required-deferral.test.ts +++ b/packages/objectql/src/engine-seed-required-deferral.test.ts @@ -231,11 +231,11 @@ describe('seed deferral vs required:true, on the real engine (#11674)', () => { new SeedLoaderService(engine as unknown as IDataEngine, emptyMetadata(), logger as any); it('MEASURED: the real engine REJECTS the deferred insert of a required id half — pass-2 write-back cannot save it', async () => { - // Keyless approval dataset BEFORE its target: the pointer cannot resolve + // Approval dataset BEFORE its target: the pointer cannot resolve // in pass 1, so the loader defers by DELETING required `record_id`. const result = await loader().load({ seeds: [ - { object: 'rq_approval', mode: 'ignore', env: ENV, records: [ + { object: 'rq_approval', externalId: 'process_name', mode: 'ignore', env: ENV, records: [ { process_name: 'flow:discount', object_name: 'rq_lead', record_id: 'Lisa Thompson', status: 'pending' }, ] }, LEAD_SEED, @@ -270,7 +270,7 @@ describe('seed deferral vs required:true, on the real engine (#11674)', () => { const result = await loader().load({ seeds: [ LEAD_SEED, - { object: 'rq_approval', mode: 'ignore', env: ENV, records: [ + { object: 'rq_approval', externalId: 'process_name', mode: 'ignore', env: ENV, records: [ { process_name: 'flow:discount', object_name: 'rq_lead', record_id: 'Lisa Thompson', status: 'pending' }, ] }, ] as any, @@ -287,12 +287,15 @@ describe('seed deferral vs required:true, on the real engine (#11674)', () => { it('MEASURED: an OPTIONAL id half on a KEYLESS dataset heals out-of-order through the real engine (#11674 end-to-end)', async () => { const result = await loader().load({ seeds: [ - { object: 'rq_ledger', mode: 'ignore', env: ENV, records: [ + // [#34857] Keyless for real: a keyed load refuses a record that leaves + // its key blank, so this dataset names no mode and the load no + // default — a request built without the parse's defaults. + { object: 'rq_ledger', env: ENV, records: [ { action: 'read', object_name: 'rq_lead', record_id: 'Lisa Thompson' }, ] }, LEAD_SEED, ] as any, - config: CONFIG, + config: { ...CONFIG, defaultMode: undefined }, }); expect(result.success).toBe(true); @@ -314,7 +317,7 @@ describe('seed deferral vs required:true, on the real engine (#11674)', () => { // signal moves when the author learns, it does not move the verdict. const result = await loader(logger).load({ seeds: [ - { object: 'rq_approval', mode: 'ignore', env: ENV, records: [ + { object: 'rq_approval', externalId: 'process_name', mode: 'ignore', env: ENV, records: [ { process_name: 'flow:discount', object_name: 'rq_lead', record_id: 'Lisa Thompson', status: 'pending' }, ] }, LEAD_SEED, @@ -343,7 +346,7 @@ describe('seed deferral vs required:true, on the real engine (#11674)', () => { const logger = silentLogger(); const result = await loader(logger).load({ seeds: [ - { object: 'rq_ledger', mode: 'ignore', env: ENV, records: [ + { object: 'rq_ledger', externalId: 'action', mode: 'ignore', env: ENV, records: [ { action: 'read', object_name: 'rq_lead', record_id: 'Lisa Thompson' }, ] }, LEAD_SEED, @@ -416,7 +419,7 @@ describe('seed deferral vs required:true, on the real engine (#11674)', () => { const logger = silentLogger(); const result = await loader(logger).load({ seeds: [ - { object: 'rq_approval_ro', mode: 'ignore', env: ENV, records: [ + { object: 'rq_approval_ro', externalId: 'process_name', mode: 'ignore', env: ENV, records: [ { process_name: 'flow:discount', object_name: 'rq_lead', record_id: 'Lisa Thompson' }, ] }, LEAD_SEED, diff --git a/packages/runtime/src/seed-loader.test.ts b/packages/runtime/src/seed-loader.test.ts index 8ee4ceab9d3..8122711bdce 100644 --- a/packages/runtime/src/seed-loader.test.ts +++ b/packages/runtime/src/seed-loader.test.ts @@ -1236,7 +1236,7 @@ describe('SeedLoaderService', () => { }); describe('load — edge cases', () => { - it('should handle records with no matching externalId field', async () => { + it('refuses a record with no value for its externalId field, writing nothing (#34857)', async () => { const metadata = createMockMetadata({ account: { name: 'account', fields: { name: { type: 'text' } } }, }); @@ -1253,8 +1253,12 @@ describe('SeedLoaderService', () => { }, }); - // Should still insert (externalId 'code' not present in record, insert path) - expect(result.summary.totalInserted).toBe(1); + // A keyed record that leaves its key blank could match no row and would + // be inserted again on every load: it is refused, by index and field. + expect(result.summary.totalInserted).toBe(0); + expect(result.summary.totalErrored).toBe(1); + expect(result.errors[0]).toMatchObject({ sourceObject: 'account', field: 'code', recordIndex: 0 }); + expect(engine.insert).not.toHaveBeenCalled(); }); it('should handle insert errors gracefully', async () => { diff --git a/packages/spec/src/migrations/entries/semantic/18.seed-key-blank-record-refused.ts b/packages/spec/src/migrations/entries/semantic/18.seed-key-blank-record-refused.ts new file mode 100644 index 00000000000..364eb6a0e5b --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.seed-key-blank-record-refused.ts @@ -0,0 +1,35 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// The upgrade-guide entry of a seed record whose externalId value is blank, +// refused at load (maintainer ruling on #34857, option B1, extended to +// single-field keys on #35336). No conversion: only the author knows the value +// that names the row. +export const entry: SemanticMigration = { + id: 'seed-key-blank-record-refused', + surface: + 'data.Seed.records (a seed dataset in `defineStack({ data })`, `defineSeed`, a `seed` metadata item, or a package ' + + 'body\'s seed) loaded in a keyed mode (`ignore`, `upsert`, `update`): a record that leaves a field of the ' + + 'dataset\'s `externalId` blank (no value, null or an empty string), whether a component of a composite key or ' + + 'the one field of a single-field key (`name` when the dataset names none)', + replacement: + 'Give the record a value for each `externalId` field, or key the dataset on fields every record carries: a field ' + + 'the object declares, a list of fields when no single field names a row, or `\'id\'` when the records carry their ' + + 'own ids', + reason: + 'A seed is replayed on every single-tenant boot, every package install or upgrade and every publish, and each ' + + 'replay matches a record to the row an earlier load wrote by the dataset\'s `externalId`. A record with a blank ' + + 'key field keyed empty, matched no row, and was written again by every `ignore` or `upsert` load (an `update` ' + + 'load skipped it), with nothing said: three loads of one such record beside a keyed one left 2, then 3, then 4 ' + + 'rows. The seed load now refuses such a record before anything of it is written: the load result carries one ' + + 'error naming the object, the record index, the blank field and the fix, the boot log says it once per dataset, ' + + 'and every other record and dataset loads, so the environment still boots. The key is read as authored, after ' + + 'expressions resolve and before references do, so a reference the load cannot resolve yet is not blank. There ' + + 'is no mechanical rewrite: the value that names the row is the author\'s to give. Rows earlier loads duplicated ' + + 'are data, not metadata, and are left as they are', + acceptanceCriteria: + 'Every seed record carries a value for each field of its dataset\'s `externalId`; after three restarts over the ' + + 'same database each seeded object holds one row per record, and neither the boot log nor the seed load result ' + + 'carries a blank-key seed refusal.', +}; From 755c75a581174ecdfbd423c0a4174ecc89479cbc Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 08:58:33 +0000 Subject: [PATCH 2/5] fix(metadata-protocol): the duplicate-fallback refusal names only the cause that still arises An upgrade now replaces a package's datasets on the shared replay list, so the refusal of two fallback sets for one object, its docblock and the seed-data page no longer name an in-process upgrade as a cause; the cause left is two packages marking the same object. The pin follows. Claude-Session: https://claude.ai/code/session_01Utp6CaysxGzF62ACvZ1x9x Co-authored-by: Claude --- .changeset/34857-seed-blank-key-record-refused.md | 2 ++ content/docs/data-modeling/seed-data.mdx | 8 +++----- .../src/seed-loader-locale-scope.test.ts | 8 ++++++-- packages/metadata-protocol/src/seed-loader.ts | 13 ++++++------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.changeset/34857-seed-blank-key-record-refused.md b/.changeset/34857-seed-blank-key-record-refused.md index 169acb8501a..6e02e0d40f7 100644 --- a/.changeset/34857-seed-blank-key-record-refused.md +++ b/.changeset/34857-seed-blank-key-record-refused.md @@ -17,3 +17,5 @@ Skills-docs: follow-up owed — skills/objectstack-data/references/seeds.md (:48 - The fix for an author: give the record a value for the blank key field, or key the dataset on fields every record carries: a field the object declares, a list of fields when no single field names a row, or `'id'` when the records carry their own ids. **Not moved.** The check reads the key as authored, after the record's expressions resolve and before any reference resolves. A reference the load defers or cannot resolve yet (a person who has not signed up) is authored, so it is not blank and its row lands and holds one row across loads, as before. A whitespace-only value is a value, as before. Rows earlier loads duplicated are data and stay; remove the extra copies yourself if they matter. A request built without the parse's defaults (no `mode` on the dataset, no `defaultMode` on the config) is not keyed and is unchanged. + +**Also: the duplicate-fallback refusal names the cause that still arises.** When the datasets being seeded mark more than one set of one object `fallback: true`, the refusal and the seed-data page no longer name "an upgrade within this process" as a cause: an upgrade now replaces a package's datasets on the replay list, so the cause left is two packages marking the same object. Wording only; what is refused is unchanged. diff --git a/content/docs/data-modeling/seed-data.mdx b/content/docs/data-modeling/seed-data.mdx index e0df69b57da..28bdc64f671 100644 --- a/content/docs/data-modeling/seed-data.mdx +++ b/content/docs/data-modeling/seed-data.mdx @@ -421,11 +421,9 @@ The rules: and the load's error (also logged at warn) names the object. Every marked set still loads for the locales it lists, exactly as an unmarked set would, and every other object still seeds. Identical copies of one set — the same - package's datasets merged twice — count once. Two versions of one package - whose marked set changed are two sets: an upgrade keeps the earlier - version's datasets on the per-organization replay list until the process - restarts, so until then an organization on an unlisted locale gets no - fallback for that object. + package's datasets merged twice — count once. An upgrade replaces the + package's datasets on the per-organization replay list, so two versions of + one package are never two sets; two packages marking the same object are. The loader logs, at info, each fallback set it loaded and the locale it filled in for. Datasets without the marker load exactly as before. diff --git a/packages/metadata-protocol/src/seed-loader-locale-scope.test.ts b/packages/metadata-protocol/src/seed-loader-locale-scope.test.ts index e74505bede9..e750dcffe92 100644 --- a/packages/metadata-protocol/src/seed-loader-locale-scope.test.ts +++ b/packages/metadata-protocol/src/seed-loader-locale-scope.test.ts @@ -478,12 +478,16 @@ describe('Seed.fallback fills in for a locale no set of the object names', () => } }); - it('names no fallback it did not use, and does not tell a correctly authored package to drop its marker', async () => { + it('names no fallback it did not use, and names the cause that still arises: more than one package marking the object', async () => { const { logger, result } = await seedUnder('ja-JP', [PRICE_BOOK_ZH_FALLBACK, PRICE_BOOK_EN_FALLBACK]); const infos = logger.info.mock.calls.map((c: any[]) => String(c[0])); expect(infos.some((m: string) => m.includes('fallback set(s) loaded'))).toBe(false); const message = result.errors[0]!.message; - expect(message).toContain('an upgrade within this process changed a package'); + expect(message).toContain("The packages being seeded mark more than one set of 'price_book'"); + expect(message).toContain('keep the marker on one'); + // An upgrade replaces a package's datasets on the replay list (#35109), + // so the refusal no longer names an upgrade in this process as a cause. + expect(message).not.toContain('upgrade'); expect(message).not.toContain('drop it from the others'); }); diff --git a/packages/metadata-protocol/src/seed-loader.ts b/packages/metadata-protocol/src/seed-loader.ts index b10e9f2e8bb..b78cb0f0fc5 100644 --- a/packages/metadata-protocol/src/seed-loader.ts +++ b/packages/metadata-protocol/src/seed-loader.ts @@ -5603,9 +5603,9 @@ function seedDeclarationFingerprint(dataset: Seed): string { * a package's datasets once per merge (boot rehydrate, install or upgrade, * reseed), and a second copy of the one fallback set is not a second choice. * Object names are global, so two packages marking the same object are two - * declarations and that object's fallback choice is refused. So are two - * versions of one package whose marked set changed: an upgrade appends the new - * version's datasets beside the old version's until the process restarts. + * declarations and that object's fallback choice is refused. (An upgrade + * replaces a package's datasets on the replay list, so two versions of one + * package do not meet here.) * * Judged whatever the load's locale: the declaration is ambiguous on every * load, not only on one that needs the fallback, and a refusal that waited for @@ -5631,10 +5631,9 @@ function findDuplicateFallbackSets(datasets: readonly Seed[]): DuplicateFallback `Seed datasets of '${object}' mark ${distinct.size} different sets \`fallback: true\` (${scopes.join('; ')}). ` + 'An object has at most one fallback set: it is the one set that loads when no other set lists the ' + `resolved locale. No fallback was used for '${object}': each marked set still loads for the locales it ` + - 'lists, and a locale none of them lists gets none of them; every other object seeds as usual. Two causes ' + - `leave more than one marked set: the packages being seeded mark more than one set of '${object}' (keep the ` + - 'marker on one), or an upgrade within this process changed a package\'s marked set (the earlier ' + - 'version\'s datasets stay on the replay list until the process restarts).', + 'lists, and a locale none of them lists gets none of them; every other object seeds as usual. The ' + + `packages being seeded mark more than one set of '${object}', most often two packages marking the same ` + + 'object: keep the marker on one.', }); } return refusals; From acdab3018ae0ad4de711fa93a7bb3cf8fe52fb6c Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 10:25:35 +0000 Subject: [PATCH 3/5] test(metadata-protocol): name the blank-key fixture's demo field sku, not code The error-code casing guard reads a lowercase literal under a code key as an error code; the field is plain demo data. Claude-Session: https://claude.ai/code/session_01Utp6CaysxGzF62ACvZ1x9x Co-authored-by: Claude --- .../src/seed-loader-empty-key-warn.test.ts | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/metadata-protocol/src/seed-loader-empty-key-warn.test.ts b/packages/metadata-protocol/src/seed-loader-empty-key-warn.test.ts index 931fb748237..260f1d57620 100644 --- a/packages/metadata-protocol/src/seed-loader-empty-key-warn.test.ts +++ b/packages/metadata-protocol/src/seed-loader-empty-key-warn.test.ts @@ -85,7 +85,7 @@ function createFaithfulEngine(): { engine: IDataEngine; store: Record = { - demo_other: { name: 'demo_other', fields: { name: { type: 'text' }, code: { type: 'text' } } }, + demo_other: { name: 'demo_other', fields: { name: { type: 'text' }, sku: { type: 'text' } } }, }; return { getObject: vi.fn(async (name: string) => objects[name]), @@ -109,7 +109,7 @@ const CONFIG = { organizationId: 'org_demo', } as any; -const dataset = (externalId: string | string[], mode = 'upsert', records: Record[] = [{ name: 'G1', code: 'g' }]) => +const dataset = (externalId: string | string[], mode = 'upsert', records: Record[] = [{ name: 'G1', sku: 'g' }]) => ({ object: 'demo_other', externalId, mode, env: ['prod', 'dev', 'test'], records }); /** The loader's blank-key refusals in a load result, by their message. */ @@ -139,9 +139,9 @@ describe('[#34857, #35336] the boot loader refuses a keyed record that leaves a for (const [label, blank] of [['empty string', ''], ['null', null], ['no value', undefined]] as const) { it(`composite key, one component ${label}: the record is not written, its siblings converge`, async () => { const blankRecord: Record = { name: 'B' }; - if (blank !== undefined) blankRecord.code = blank; + if (blank !== undefined) blankRecord.sku = blank; const { store, counts, results, loggers } = await threeLoads([ - dataset(['name', 'code'], 'upsert', [{ name: 'A', code: 'a' }, blankRecord, { name: 'C', code: 'c' }]), + dataset(['name', 'sku'], 'upsert', [{ name: 'A', sku: 'a' }, blankRecord, { name: 'C', sku: 'c' }]), ]); expect(counts).toEqual([2, 2, 2]); @@ -151,11 +151,11 @@ describe('[#34857, #35336] the boot loader refuses a keyed record that leaves a expect(result.results[0]).toMatchObject({ object: 'demo_other', errored: 1, total: 3 }); const refused = blankKeyRefusals(result); expect(refused).toHaveLength(1); - expect(refused[0]).toMatchObject({ sourceObject: 'demo_other', field: 'code', recordIndex: 1 }); + expect(refused[0]).toMatchObject({ sourceObject: 'demo_other', field: 'sku', recordIndex: 1 }); expect(refused[0].message).toContain( - "Seed record #1 of 'demo_other' was NOT loaded: it is keyed on externalId 'name+code' and leaves 'code' blank", + "Seed record #1 of 'demo_other' was NOT loaded: it is keyed on externalId 'name+sku' and leaves 'sku' blank", ); - expect(refused[0].message).toContain("Give the record a value for 'code'"); + expect(refused[0].message).toContain("Give the record a value for 'sku'"); } // Logged once per load, at `error`: the record is dropped. for (const logger of loggers) expect(blankKeyLines(logger)).toHaveLength(1); @@ -163,19 +163,19 @@ describe('[#34857, #35336] the boot loader refuses a keyed record that leaves a } it('single-field key: a record with no value for it is refused; its keyed sibling converges', async () => { - const { counts, results } = await threeLoads([dataset('code', 'upsert', [{ name: 'A', code: 'a' }, { name: 'B' }])]); + const { counts, results } = await threeLoads([dataset('sku', 'upsert', [{ name: 'A', sku: 'a' }, { name: 'B' }])]); expect(counts).toEqual([1, 1, 1]); for (const result of results) { const refused = blankKeyRefusals(result); expect(refused).toHaveLength(1); - expect(refused[0]).toMatchObject({ sourceObject: 'demo_other', field: 'code', recordIndex: 1 }); - expect(refused[0].message).toContain("keyed on externalId 'code' and leaves 'code' blank"); + expect(refused[0]).toMatchObject({ sourceObject: 'demo_other', field: 'sku', recordIndex: 1 }); + expect(refused[0].message).toContain("keyed on externalId 'sku' and leaves 'sku' blank"); } }); it('the default key (`name`, no externalId declared): a record with no name is refused, and the message says the key is the default', async () => { - const seed = { object: 'demo_other', mode: 'ignore', env: ['prod', 'dev', 'test'], records: [{ name: 'A', code: 'a' }, { code: 'b' }] }; + const seed = { object: 'demo_other', mode: 'ignore', env: ['prod', 'dev', 'test'], records: [{ name: 'A', sku: 'a' }, { sku: 'b' }] }; const { counts, results } = await threeLoads([seed]); expect(counts).toEqual([1, 1, 1]); @@ -188,17 +188,17 @@ describe('[#34857, #35336] the boot loader refuses a keyed record that leaves a it('an expression that evaluates empty in a key field is refused the same way (it is read after expressions resolve)', async () => { // `os.user.id` is null at seed time when no identity is supplied. const { counts, results } = await threeLoads([ - dataset(['name', 'code'], 'upsert', [{ name: 'A', code: 'a' }, { name: 'B', code: { dialect: 'cel', source: 'os.user.id' } }]), + dataset(['name', 'sku'], 'upsert', [{ name: 'A', sku: 'a' }, { name: 'B', sku: { dialect: 'cel', source: 'os.user.id' } }]), ]); expect(counts).toEqual([1, 1, 1]); const refused = blankKeyRefusals(results[0]); expect(refused).toHaveLength(1); - expect(refused[0]).toMatchObject({ field: 'code', recordIndex: 1 }); + expect(refused[0]).toMatchObject({ field: 'sku', recordIndex: 1 }); }); it('an `update` dataset reports the record instead of skipping it in silence', async () => { - const { results } = await threeLoads([dataset('code', 'update', [{ name: 'B' }])]); + const { results } = await threeLoads([dataset('sku', 'update', [{ name: 'B' }])]); const refused = blankKeyRefusals(results[0]); expect(refused).toHaveLength(1); expect(refused[0].message).toContain('so an update load can never find the row it names'); @@ -209,7 +209,7 @@ describe('[#34857, #35336] the boot loader refuses a keyed record that leaves a const { engine } = createFaithfulEngine(); const logger = createLogger(); const result = await new SeedLoaderService(engine, createMetadata(), logger).load({ - seeds: [dataset('code', 'upsert', [{ name: 'B' }])] as any[], config: { ...CONFIG, dryRun: true }, + seeds: [dataset('sku', 'upsert', [{ name: 'B' }])] as any[], config: { ...CONFIG, dryRun: true }, }); expect(blankKeyRefusals(result)).toHaveLength(1); expect(blankKeyLines(logger)).toEqual([]); @@ -217,7 +217,7 @@ describe('[#34857, #35336] the boot loader refuses a keyed record that leaves a it('CONTROL: a fully keyed dataset converges on replay, refuses nothing and says nothing', async () => { const { counts, results, loggers } = await threeLoads([ - dataset(['name', 'code'], 'upsert', [{ name: 'A', code: 'a' }, { name: 'B', code: 'b' }]), + dataset(['name', 'sku'], 'upsert', [{ name: 'A', sku: 'a' }, { name: 'B', sku: 'b' }]), ]); expect(counts).toEqual([2, 2, 2]); @@ -232,7 +232,7 @@ describe('[#34857, #35336] the boot loader refuses a keyed record that leaves a }); it('CONTROL: a whitespace-only key value is a value, as before (no trim)', async () => { - const { counts, results } = await threeLoads([dataset('code', 'upsert', [{ name: 'A', code: ' ' }])]); + const { counts, results } = await threeLoads([dataset('sku', 'upsert', [{ name: 'A', sku: ' ' }])]); expect(counts).toEqual([1, 1, 1]); expect(blankKeyRefusals(results[0])).toEqual([]); }); @@ -241,7 +241,7 @@ describe('[#34857, #35336] the boot loader refuses a keyed record that leaves a describe('[#28952] the boot loader — a keyed dataset whose every record keys empty', () => { it('refuses every record, one error each in the result, one line logged per dataset, and never writes', async () => { const { store, counts, results, loggers } = await threeLoads([ - dataset('no_such_field', 'upsert', [{ name: 'G1', code: 'g' }, { name: 'G2', code: 'h' }]), + dataset('no_such_field', 'upsert', [{ name: 'G1', sku: 'g' }, { name: 'G2', sku: 'h' }]), ]); expect(counts).toEqual([0, 0, 0]); @@ -264,12 +264,12 @@ describe('[#28952] the boot loader — a keyed dataset whose every record keys e const { engine } = createFaithfulEngine(); const logger = createLogger(); const result = await new SeedLoaderService(engine, createMetadata(), logger).load({ - seeds: [dataset(['code', 'no_such_field'], 'ignore')] as any[], config: CONFIG, + seeds: [dataset(['sku', 'no_such_field'], 'ignore')] as any[], config: CONFIG, }); const refused = blankKeyRefusals(result); expect(refused).toHaveLength(1); expect(refused[0]).toMatchObject({ field: 'no_such_field', recordIndex: 0 }); - expect(refused[0].message).toContain("keyed on externalId 'code+no_such_field' and leaves 'no_such_field' blank"); + expect(refused[0].message).toContain("keyed on externalId 'sku+no_such_field' and leaves 'no_such_field' blank"); }); it('control: a retired `insert` dataset is refused before any key is read, so it carries no blank-key refusal (#34613)', async () => { From d56b6f80c17b62bb829152d0b176cceea06b61bd Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 11:17:57 +0000 Subject: [PATCH 4/5] chore(changeset): name the skills-docs follow-up card #35480 Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01Utp6CaysxGzF62ACvZ1x9x --- .changeset/34857-seed-blank-key-record-refused.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/34857-seed-blank-key-record-refused.md b/.changeset/34857-seed-blank-key-record-refused.md index 6e02e0d40f7..4cb739b1940 100644 --- a/.changeset/34857-seed-blank-key-record-refused.md +++ b/.changeset/34857-seed-blank-key-record-refused.md @@ -6,7 +6,7 @@ fix(metadata-protocol)!: a seed record that leaves a key field blank is refused Clause-②: no (narrowing) Metadata-protocol: narrowed -Skills-docs: follow-up owed — skills/objectstack-data/references/seeds.md (:48 the externalId row, :68 the composite key, :93 `externalId` selection: none says a record must carry every key field or is refused at load) +Skills-docs: follow-up #35480 — skills/objectstack-data/references/seeds.md (:48 the externalId row, :68 the composite key, :93 `externalId` selection: none says a record must carry every key field or is refused at load) From 8aa97502e42b6f561a89cfedfc6a74a9b63bd2f9 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 11:31:16 +0000 Subject: [PATCH 5/5] fix(metadata-protocol): blank-key refusal names the default key from the parsed request The default-key hint in the blank-key refusal fired only for an undeclared externalId, which a parsed request never carries (the parse defaults it to name). The hint now rides on a single-field key of name: the message says name is also the key a dataset gets when it names none. The pin goes through SeedLoaderRequestSchema.parse. The protocol.ts docblock no longer says the boot loader never refuses, and the seed-data docs say the key is read after the record's expressions resolve. Claude-Session: https://claude.ai/code/session_01Utp6CaysxGzF62ACvZ1x9x Co-authored-by: Claude --- content/docs/data-modeling/seed-data.mdx | 5 +-- packages/metadata-protocol/src/protocol.ts | 6 ++-- .../src/seed-loader-empty-key-warn.test.ts | 33 ++++++++++++++++--- packages/metadata-protocol/src/seed-loader.ts | 11 +++++-- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/content/docs/data-modeling/seed-data.mdx b/content/docs/data-modeling/seed-data.mdx index 28bdc64f671..8ee1bd8992a 100644 --- a/content/docs/data-modeling/seed-data.mdx +++ b/content/docs/data-modeling/seed-data.mdx @@ -81,8 +81,9 @@ names none). A record that leaves one blank (no value, `null` or `''`) could mat row and would be inserted again on every replay, so the load refuses it: nothing of it is written, the load reports an error naming the object, the record and the blank field, and the dataset's other records load. The check reads the key as written in the -seed, so a reference the load cannot resolve yet (a person who has not signed up) is -not blank. +seed, after the record's expressions resolve, so an expression that comes out empty is +refused, while a reference the load cannot resolve yet (a person who has not signed +up) is not blank. The unkeyed modes `insert` and `replace` are retired: see [Moving off `insert` and `replace`](#moving-off-insert-and-replace). diff --git a/packages/metadata-protocol/src/protocol.ts b/packages/metadata-protocol/src/protocol.ts index a41ea1fd0f2..bca4c76cdc0 100644 --- a/packages/metadata-protocol/src/protocol.ts +++ b/packages/metadata-protocol/src/protocol.ts @@ -9077,9 +9077,9 @@ export class ObjectStackProtocolImplementation implements * Answered as the schema gate answers, with the envelope of * {@link unknownDatasourceSaveRefusal}: `422 INVALID_METADATA`, one finding * per missing member at `externalId` (`externalId.N` for a composite - * member), naming the field and the object. The boot loader - * never refuses; it warns once for a keyed dataset whose every record - * keys empty ({@link SeedLoaderService}). + * member), naming the field and the object. The boot loader refuses + * each keyed record that leaves a key field blank, one error per + * record, and loads the rest ({@link SeedLoaderService}). */ private seedExternalIdSaveRefusal( singularType: string, diff --git a/packages/metadata-protocol/src/seed-loader-empty-key-warn.test.ts b/packages/metadata-protocol/src/seed-loader-empty-key-warn.test.ts index 260f1d57620..c8813295ad6 100644 --- a/packages/metadata-protocol/src/seed-loader-empty-key-warn.test.ts +++ b/packages/metadata-protocol/src/seed-loader-empty-key-warn.test.ts @@ -2,6 +2,7 @@ import { describe, it, expect, vi } from 'vitest'; import { SeedLoaderService } from './seed-loader.js'; +import { SeedLoaderRequestSchema } from '@objectstack/spec/data'; import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts'; import { assertEngineDeleteDispatch, assertEngineUpdateDispatch, assertEngineFindOnePredicate } from '@objectstack/metadata-core'; @@ -174,15 +175,37 @@ describe('[#34857, #35336] the boot loader refuses a keyed record that leaves a } }); - it('the default key (`name`, no externalId declared): a record with no name is refused, and the message says the key is the default', async () => { - const seed = { object: 'demo_other', mode: 'ignore', env: ['prod', 'dev', 'test'], records: [{ name: 'A', sku: 'a' }, { sku: 'b' }] }; - const { counts, results } = await threeLoads([seed]); + it('the default key (`name`, no externalId declared), through a parsed request: a record with no name is refused, and the message says `name` is also the default key', async () => { + // Every production caller parses its request first, and the parse + // defaults `externalId` to `name`: the loader never sees "undeclared". + const request = SeedLoaderRequestSchema.parse({ + seeds: [{ object: 'demo_other', mode: 'ignore', records: [{ name: 'A', sku: 'a' }, { sku: 'b' }] }], + config: CONFIG, + }); + expect(request.seeds[0].externalId).toBe('name'); + const { engine, store } = createFaithfulEngine(); + const counts: number[] = []; + let first: any; + for (let boot = 0; boot < 3; boot++) { + const result = await new SeedLoaderService(engine, createMetadata(), createLogger()).load(request); + first ??= result; + counts.push(store.demo_other.length); + } expect(counts).toEqual([1, 1, 1]); - const refused = blankKeyRefusals(results[0]); + const refused = blankKeyRefusals(first); expect(refused).toHaveLength(1); expect(refused[0]).toMatchObject({ field: 'name', recordIndex: 1 }); - expect(refused[0].message).toContain("keyed on externalId 'name' (the default key when a dataset names none) and leaves 'name' blank"); + expect(refused[0].message).toContain( + "keyed on externalId 'name' (also the key a dataset gets when it names none) and leaves 'name' blank", + ); + }); + + it('an authored key other than `name` carries no default-key hint', async () => { + const { results } = await threeLoads([dataset(['name', 'sku'], 'upsert', [{ sku: 'a' }])]); + const [refused] = blankKeyRefusals(results[0]); + expect(refused.message).toContain("keyed on externalId 'name+sku' and leaves 'name' blank"); + expect(refused.message).not.toContain('names none'); }); it('an expression that evaluates empty in a key field is refused the same way (it is read after expressions resolve)', async () => { diff --git a/packages/metadata-protocol/src/seed-loader.ts b/packages/metadata-protocol/src/seed-loader.ts index b78cb0f0fc5..b1a215ad8db 100644 --- a/packages/metadata-protocol/src/seed-loader.ts +++ b/packages/metadata-protocol/src/seed-loader.ts @@ -476,17 +476,22 @@ function isBlankSeedKeyValue(value: unknown): boolean { * object, the record, the blank field(s) and the fix; the fix covers both * shapes it arises from: one record missing a value its siblings carry, and a * dataset whose `externalId` names a field no record carries. + * + * A key of `name` alone says it is also the key a dataset gets when it names + * none: the parse defaults `externalId` to `name` before any load sees it, so + * whether the author wrote it cannot be told here, and an author who never + * wrote one is the commonest reader of this refusal. */ function blankSeedKeyRefusal( objectName: string, recordIndex: number, externalId: string | string[], - defaultKey: boolean, blankFields: readonly string[], mode: string | undefined, ): ReferenceResolutionError { const fields = Array.isArray(externalId) ? externalId : [externalId]; - const keyLabel = `externalId '${fields.join('+')}'${defaultKey ? ' (the default key when a dataset names none)' : ''}`; + const defaultKey = fields.length === 1 && fields[0] === DEFAULT_EXTERNAL_ID_FIELD; + const keyLabel = `externalId '${fields.join('+')}'${defaultKey ? ' (also the key a dataset gets when it names none)' : ''}`; const blank = blankFields.map((field) => `'${field}'`).join(', '); const consequence = mode === 'update' ? 'so an update load can never find the row it names' @@ -2341,7 +2346,7 @@ export class SeedLoaderService implements ISeedLoaderService { const blankKeyFields = [...keyFields].filter((field) => isBlankSeedKeyValue(record[field])); if (blankKeyFields.length > 0) { errored++; - const error = blankSeedKeyRefusal(objectName, i, externalId, dataset.externalId === undefined, blankKeyFields, mode); + const error = blankSeedKeyRefusal(objectName, i, externalId, blankKeyFields, mode); errors.push(error); allErrors.push(error); // `error` (#4632): the record is dropped. Said once per dataset — the