Repository navigation
Commit de395b4
fix(metadata-protocol)!: a seed record that leaves a key field blank is refused at load (#35459)
Fixes #34857
Also delivers (folded, closed by the area at close-out): #35336, #35376
Clause-②: no (narrowing)
Metadata-protocol: narrowed
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)
## 维护者速读
-
用户能看到什么变化:种子数据里某条记录缺了用来识别它的键值(比如没填名称),以前每次启动、安装或升级都会悄悄多插一行;现在这一条不再写入,加载结果写明是哪个对象的第几条、缺哪个字段、怎么改,其余数据照常加载。另外「同一对象有两个兜底语种集」的报错不再提已经不存在的「进程内升级」原因。
- 为什么做:安装、升级与启动可靠性(种子数据生命周期);修的是作者自写种子每次加载重复插行且无提示的问题。
- 出错会怎样:故意留空键值的作者,这条记录在新环境里不再出现(以前是每次多一行);已经重复的行不会被清理;撤回本次合并即可恢复旧行为。
- 要你做什么:无。
## 席位核对
### What changes
Ruling B1 (record 7000515976), extended to single-field keys (record
7000600379).
- `packages/metadata-protocol/src/seed-loader.ts`: in `loadDataset`'s
record loop, for the keyed modes (`ignore`, `upsert`, `update`), a
record that leaves a field of its `externalId` blank (`undefined`,
`null` or `''`; any component of a composite key, or the single field,
`name` by default) is refused: `errored++`, one
`ReferenceResolutionError` (`field` = the blank field(s), `targetField:
'(externalId)'`, `recordIndex`), one `logger.error` per dataset (none on
a dry run), `continue`. The check sits where the authored key is read:
after `resolveSeedRecord` (expressions) and the organization stamp,
BEFORE any reference resolves, so a deferred reference (#34800 / #34856)
still holds its authored value and is never caught. The blank rule is
the one `seedLandedKey` / `externalIdKey` already key `''` by, now one
helper `isBlankSeedKeyValue`; whitespace is a value (A3, unchanged).
- A2 choice: the per-record refusal REPLACES the #28952 dataset-level
`warn`. That warn said "every record is written as a new row, on every
load", which is false once nothing is written, and a dataset-level line
on top of per-record errors would report the same records twice. The
per-record message carries the #28952 prescription too (key the dataset
on fields every record carries, a list, or `'id'`). The boot log says it
once per dataset.
- `findDuplicateFallbackSets` (#35376, PR #35374 merged
2026-11-19T08:44Z before this PR opened): refusal text and docblock name
only the cause that still arises, two packages marking one object.
- Docs `content/docs/data-modeling/seed-data.mdx`: Import Modes states
the rule; the composite-key section says every listed field is carried;
the `TestUser` example (records with no `name`) gains `externalId:
'email'` (A4); the fallback bullet drops the stale in-process-upgrade
cause (#35376).
- ADR-0087 ledger entry
`packages/spec/src/migrations/entries/semantic/18.seed-key-blank-record-refused.ts`
(data only, no export, no Zod change; authorized by the PM for this
narrowing), marked `registered seed-key-blank-record-refused` in the
changeset.
### Tests
New pins (shared-harness rule, top-level describes in existing harness
files):
- `seed-loader-empty-key-warn.test.ts`: composite key with one component
`''` / `null` / omitted (three loads: 2, 2, 2 rows; error names object,
index 1, field `sku`, fix), single-field `sku`, default `name` through a
parsed request (`SeedLoaderRequestSchema.parse`, no `externalId`: the
message reads "keyed on externalId 'name' (also the key a dataset gets
when it names none) and leaves 'name' blank"), CONTROL an authored
`name`+`sku` key gets no such hint, an expression evaluating empty
(`os.user.id`) refused, `update` reports instead of skipping silently,
dry run reports and logs nothing, CONTROL fully keyed dataset converges
and says nothing, CONTROL whitespace-only value is a value. The #28952
describe flips: every record refused, one error each, one line per
dataset, no `warn`.
- `seed-loader-deferred-key-reference.test.ts`: CONTROL `ignore` and
`upsert`, a deferred key reference is not refused, three loads one row;
CONTROL a key reference authored `''` beside it is refused. The #34856
delete describe in the same file stays green.
Fixture triage (what each pinned is kept):
- `seed-loader-deferred-dropped.test.ts` (reverse pin): its keyless
device was a blank `region` in a keyed dataset, now refused. Remade, not
deleted: the department dataset names no `mode` and the load config no
`defaultMode` (a request built without the parse's defaults, the one
load that still writes a row keyed `''`), so pass-2 write-back by
captured id stays pinned on a written keyless row. Added: the KEYED
blank-component record is refused before it writes or defers anything.
- `seed-loader-pointer-pair.test.ts`: `insertSeed` keyed on `id` with no
ids now gives each record its id; the KEYLESS heal case moves to the
same mode-less device.
- `seed-loader-composite-key-diagnostic.test.ts`: the ruling's pair
`('a','b')` / `('a\0b','')` — the second is now refused, still never
matched to the first.
- `protocol.seed-external-id-refusal.test.ts`: the `externalId: 'id'`
control's record carries an id.
- `packages/objectql/src/engine-seed-required-deferral.test.ts`:
datasets with no `externalId` (default `name`) and no `name` get
`externalId: 'process_name'` / `'action'`; the KEYLESS heal case uses
the mode-less device.
- `packages/runtime/src/seed-loader.test.ts`: "should handle records
with no matching externalId field" pinned the insert; flipped to the
refusal.
- `seed-loader-locale-scope.test.ts`: #35376's pin follows the new text.
### Acceptance notes
- A1 (measured on 35c6331 with a copy of the base loader, three loads
each): single `code` 2, 3, 4 rows, 0 warn, 0 error; default `name` 2, 3,
4; composite `''` 2, 3, 4; composite `null` (`ignore`) 2, 3, 4. With the
fix: 1, 1, 1 and one error per load.
- Stock: the dogfood battery boots every example app; zero blank-key
refusals in its log.
- Departs from PR #29066's seat route ("the boot loader never refuses"),
by the maintainer's ruling. A boot still does not fail (`haltOnError:
false`).
- The mode-less load (no `mode`, no `defaultMode`) is left unkeyed on
purpose; nothing in this PR changes it.
- Not changed: rows earlier loads duplicated stay.
- `seed-loader-locale-scope.test.ts` "an upgrade that changed the marked
set (versions 1 and 2 on one list)" still feeds both versions straight
to the loader; its comment describes the pre-#35374 replay list. Left as
is: the loader still refuses that input from a direct caller.
### Verification
All readings on head `755c75a5` (the fold commit `64abfecd`, one merge
of `origin/main` `a9b36eff`, the #35376 commit) unless named.
<details><summary>Tests and typecheck</summary>
- `pnpm --filter @objectstack/metadata-protocol test`: `Test Files 358
passed | 9 skipped (367)`, `Tests 23238 passed | 45 skipped (23283)`.
- `pnpm --filter @objectstack/metadata-protocol --filter
@objectstack/runtime --filter @objectstack/objectql typecheck`: exit 0.
- Re-keyed consumer files: runtime `src/seed-loader.test.ts
src/seed-datasets.test.ts src/app-plugin.seed-locale-producer.test.ts`
`Tests 93 passed (93)`; objectql
`src/engine-seed-required-deferral.test.ts` `Tests 7 passed (7)`.
- Consumer sweep on `64abfecd`'s tree (dist rebuilt): every test file
outside this package that names the seed loader or authors seed records,
run in runtime (36 files), objectql (26), cloud-connection (26), rest
(10), metadata (4), plugins/organizations (5), cli unit tier (3): all
green after the two re-keyed files above; integration-tier cli files
declared to CI.
- Dogfood battery (narrowing arm), `pnpm --filter @objectstack/dogfood
test` after the `@objectstack/dogfood^...` build, on `755c75a5`: `Test
Files 482 passed | 3 skipped (485)`, `Tests 4092 passed | 68 skipped
(4160)`, lock verdict `command-exit 0`; zero blank-key refusals in the
boot logs.
</details>
<details><summary>Ablation (restored, blob equals HEAD, `git diff HEAD`
empty)</summary>
- `scripts/ablation-replace.mjs` on `seed-loader.ts`: `const
blankKeyFields = [...keyFields].filter(...)` replaced by `const
blankKeyFields: string[] = [];` (anchor 1 to 0, blob `b10e9f2e` to
`23591f6e`). `seed-loader-empty-key-warn.test.ts` +
`seed-loader-deferred-key-reference.test.ts`: `Tests 11 failed | 22
passed (33)`; the 11 are every refusal pin, the 22 include every
CONTROL. Restored: blob `b10e9f2e` equals HEAD. No build involved: the
pins import `./seed-loader.js` from source.
</details>
<details><summary>Gates</summary>
- `dispatch-gates.mjs --commands` derives 117 families (the diff touches
`packages/spec`). Run locally on `755c75a5`, all exit 0:
`check-adr-0087-registration` (with `--self-test`; reads `registered
seed-key-blank-record-refused (new here)`), `check-changeset-no-major`,
`check-empty-changeset`, `check:nul-bytes`, `check:doc-authoring`,
`check:durability-log-level`, `check:issue-citations`,
`check:doc-anchors`, `check:docs-single-h1`, `check:doc-frontmatter`,
`check:startup-registry-verdict`, `check:engine-double-contract`,
`docs-audit/check-affected-docs`, `check:cross-package-test-inputs`,
`check:test-source-alias`, spec `check:upgrade-guide`, spec
`check:spec-changes`, `check:type-check-coverage`,
`check:type-check-debt`, `check:dts-closure`. The other derived families
are declared to CI (`--ran`: 21 run, the rest UNRUN locally).
- `overlap-check.mjs --branch=HEAD`: `VERDICT clean exit 0` (shares one
test file with open PR #35388, merges cleanly).
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CaysxGzF62ACvZ1x9x)_
<!-- signed: repo:objectstack#5 · os-bill ·
session_01Utp6CaysxGzF62ACvZ1x9x -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 97f3420 commit de395b4
14 files changed
Lines changed: 504 additions & 138 deletions
File tree
- .changeset
- content/docs/data-modeling
- packages
- metadata-protocol/src
- objectql/src
- runtime/src
- spec/src/migrations/entries/semantic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
79 | 87 | | |
80 | 88 | | |
81 | 89 | | |
| |||
311 | 319 | | |
312 | 320 | | |
313 | 321 | | |
| 322 | + | |
314 | 323 | | |
315 | 324 | | |
316 | 325 | | |
| |||
413 | 422 | | |
414 | 423 | | |
415 | 424 | | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
421 | 428 | | |
422 | 429 | | |
423 | 430 | | |
| |||
608 | 615 | | |
609 | 616 | | |
610 | 617 | | |
611 | | - | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
612 | 621 | | |
613 | 622 | | |
614 | 623 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9077 | 9077 | | |
9078 | 9078 | | |
9079 | 9079 | | |
9080 | | - | |
9081 | | - | |
9082 | | - | |
| 9080 | + | |
| 9081 | + | |
| 9082 | + | |
9083 | 9083 | | |
9084 | 9084 | | |
9085 | 9085 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
348 | | - | |
| 348 | + | |
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
369 | 373 | | |
370 | 374 | | |
371 | 375 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
133 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
134 | 143 | | |
135 | 144 | | |
136 | 145 | | |
137 | | - | |
| 146 | + | |
138 | 147 | | |
139 | 148 | | |
140 | 149 | | |
| |||
147 | 156 | | |
148 | 157 | | |
149 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
150 | 165 | | |
151 | 166 | | |
152 | 167 | | |
| |||
171 | 186 | | |
172 | 187 | | |
173 | 188 | | |
174 | | - | |
175 | | - | |
| 189 | + | |
| 190 | + | |
176 | 191 | | |
177 | 192 | | |
178 | 193 | | |
| |||
200 | 215 | | |
201 | 216 | | |
202 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
203 | 237 | | |
204 | 238 | | |
205 | 239 | | |
206 | 240 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
215 | 247 | | |
216 | 248 | | |
217 | 249 | | |
| |||
226 | 258 | | |
227 | 259 | | |
228 | 260 | | |
229 | | - | |
230 | | - | |
| 261 | + | |
| 262 | + | |
231 | 263 | | |
232 | 264 | | |
233 | 265 | | |
| |||
400 | 432 | | |
401 | 433 | | |
402 | 434 | | |
403 | | - | |
404 | | - | |
| 435 | + | |
| 436 | + | |
405 | 437 | | |
406 | 438 | | |
407 | 439 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
0 commit comments