Repository navigation
fix(core): resolve an import lookup cell by the target object's unique fields, an autonumber included - #28112
Conversation
…s, an autonumber included resolveRef asked the id, the lookup's displayField, the target's title field and the fixed human keys, then stopped, so a cell holding the target's autonumber or another unique field answered reference_not_found. The target's unique fields (isUniqueDeclared, plus an autonumber that omits unique, the spec's contract default) are now asked last, in declared order, de-duplicated, virtual fields still skipped. First match wins; more than one record on a field is still reference_ambiguous. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4czVnUdQQCVKSW5J2uk
📓 Docs Drift CheckThis PR changes 1 package(s): 6 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 4 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 39 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 16bd145f90875d530b5971bed276f25d3d59600a && git checkout 16bd145f90875d530b5971bed276f25d3d59600a
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 121d1a5ffbf716bf1c3fc56e17f6eafe9fff804d 721c634a00b7e03ebd2e3790e1f11a6c37321771 && git checkout -B drift-repro 121d1a5ffbf716bf1c3fc56e17f6eafe9fff804d && git merge --no-ff 721c634a00b7e03ebd2e3790e1f11a6c37321771
node scripts/docs-audit/affected-docs.mjs --json 121d1a5ffbf716bf1c3fc56e17f6eafe9fff804d
|
|
domain:server#1 · os-elon-musk · session_016WV4czVnUdQQCVKSW5J2uk Seat ACCEPT · PR #28112 · head
|
Fixes #27947
Clause-②: no
Metadata-protocol: none
Skills-docs: none —
skills/**andcontent/docs/**(outside the generatedreferences/and the release-ownedreleases/) carry no sentence listing the import lookup candidate fields; grepped for the fixed keys,reference_not_found,reference_ambiguousand the lookup-cell wording.维护者速读
unique声明了约束的字段,以及未写unique的 autonumber 字段)。ACC-000012)或其它唯一字段时,今天一律报reference_not_found;记录标题一改,之前导出的文件就全部导不回来。reference_ambiguous,不会静默挑一条。回滚即还原import-runner.ts这一处候选列表。packages/core/src/utils/import-runner.ts的isUniqueReferenceField(autonumber 默认唯一、unique: false退出)与resolveRef候选列表末尾一行;其次import-runner-reference-unique.test.ts。pnpm --filter @objectstack/core exec vitest run src/utils/import-runner-reference-unique.test.ts,预期 6 个用例全绿。What changes
resolveRefinpackages/core/src/utils/import-runner.tsasked the id, the lookup'sdisplayField, the target's title field, thenname/title/label/full_name/email/username, and stopped. A cell holding the target's autonumber or another unique field answeredreference_not_found.The target's unique fields are now appended to the candidate list, read once per target per import off the same declaration the exposure check already reads (
servesReferenceTarget), so no extra metadata read:uniquedeclares a constraint, judged by the spec's ownisUniqueDeclared(true,'organization','global');autonumberfield that omitsunique: the spec makes itunique: 'organization'by contract (FieldSchema's autonumber default). The default is applied in the predicate too, so a declaration read unparsed still counts;autonumberdeclaredunique: falsehas opted out (the spec's display-only ordinal) and is not asked.They come after every existing candidate, in the target's declared field order, de-duplicated against the existing list (a unique
emailis asked once, in its fixed place), and virtual fields are still skipped. The existing rules are unchanged: the first field to match wins, and a field matching more than one record isreference_ambiguous.No spec key, no published shape and no public export changes.
Tests
New
packages/core/src/utils/import-runner-reference-unique.test.ts(6 cases), beside the#24981title pins:ACC-000012resolves and stores the matched id, asked after every existing candidate;unique: true) resolves;nameand another record's autonumber links thenamematch, and the autonumber is never asked;reference_not_found, after asking the unique fields in declared order, the uniqueemailonce, the opted-out autonumber never;reference_not_found;reference_ambiguousand links neither.Measured on
main8cb8c7f before the fix: 4 of 6 red, the autonumber cell answeringreference_not_found(expected ok: true, receivedcode: "reference_not_found",field: "account").Ablations on the fix commit, each restored from
HEADafter the run:unique: falseopt-outAcceptance notes
reference_not_found(misses are not cached, as before, so a repeated unmatched cell repeats them). Matching cells cost what they did.organization-scoped unique field read across organizations can answer two records; that is reportedreference_ambiguous, never a silent pick.Verification
node scripts/pm/dispatch-gates.mjs --commandsderives for this diff, exit codes captured, reconciled with--ran;pnpm lint. Counts are in the os-dev report on the card.🤖 Generated with Claude Code
https://claude.ai/code/session_016WV4czVnUdQQCVKSW5J2uk