Repository navigation
Commit 85f2ac5
fix(metadata-protocol): a seed owner_id naming a person resolves on objects that rely on the injected owner column (#34023)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbKnsd8ZLsq9hBbRRm5JvJb2)_
Fixes #33791
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:种子数据加载时,业务对象若依赖平台自动注入的 `owner_id`(自己没声明),种子里写的人名现在会像
`Field.user()` 一样解析成该用户的 id;该人不是本组织成员时留空并报「not a member」错误。
- 为什么改:之前这类对象(多数业务对象,如 HotCRM 的
invoice、payment)会把人名原样存成文本,不报错也不记日志;记录归属于一个不存在的用户,首位管理员接管也认领不到它。
- 风险与回滚:只改种子引用图的构建,声明了 `owner_id` 的对象和不注入 owner
的对象不受影响;已存的文本值不会被本改动改写。回滚即撤回本 PR。
-
先看:`packages/metadata-protocol/src/seed-loader.ts`(`seedReferenceGraphFields`
与 `buildDependencyGraph`
中的一行调用)、`packages/runtime/src/seed-org-scoped-references.integration.test.ts`(桩改为返回作者原始定义
+ 新的 #33791 用例组)。
- 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run
src/seed-org-scoped-references.integration.test.ts`,预期 31 个用例全部通过,其中
#33791 组 5 个。
- 需要你做的:无,席位落地。
## What changes
The seed loader builds its reference graph from the definition the
metadata service serves, which is the one the author wrote. An object
that relies on the platform's `owner_id` does not declare it: objectql's
system-field pass adds it at registration. `buildDependencyGraph` read
the declared fields only, so a seed `owner_id: 'PERSON NAME'` on such an
object was stored as the name itself, while a declared `Field.user()` /
`Field.lookup('sys_user')` on the same row resolved.
- `seed-loader.ts`: a new `seedReferenceGraphFields(definition)` returns
the declared fields plus `owner_id` as `OWNER_FIELD_DEF` (the `sys_user`
lookup the registry injects) when
`resolveInjectedSystemColumns(definition).owner` is true and the object
does not declare `owner_id`. `buildDependencyGraph` iterates that map. A
declared `owner_id` wins whatever its type; objects with no injected
owner (`ownership: 'org' | 'none' | 'business_unit'`, `managedBy`, a
`sys_*` name, `systemFields: false`) are unchanged. The injected owner
then takes the same resolution path as a declared person lookup:
unscoped on a load with no organization, membership-scoped on an
organization's own load, NULL plus the "not a member of organization"
error for a non-member.
- `seed-org-scoped-references.integration.test.ts`: the metadata stub
now serves the as-authored definition (it served
`engine.registry.getObject(...)`, the enriched one, which hid this
defect). The existing #33207 case that seeds `owner_id: 'Zhang Wei'` on
`crm_deal` turned red on `origin/main` once the stub was corrected, and
is green with the fix. A new top-level describe pins single boot, walled
replay (member, same-name per organization, non-member NULL + error on
both `owner_id` and `rep`), the pinned install load, and the
no-organization control.
- `seed-loader-injected-owner-reference.test.ts` (new): graph-level pins
on authored definitions: the injected row, its equality with a declared
`sys_user` lookup named `owner_id`, a declared `owner_id` winning, a
declared non-reference `owner_id`, the six no-owner boundary objects,
and `sys_user` ordering with no cycle.
- `seed-loader-reference-carrier.test.ts`,
`seed-loader-implicit-reference-target.test.ts`: their fixtures (`book`,
`crm_task`) are user-owned objects, so the graph now also carries an
`owner_id` row for them. Their assertions judge the declared carrier
field, so they now read the declared field's rows only (fixture triage:
the fixtures are unchanged; the new row is correct for them).
- Changeset: `@objectstack/metadata-protocol` patch.
## Tests
All readings below are on head `03ff3585` (after merging `origin/main`
at `b8ac0e24`) unless named otherwise.
- `@objectstack/metadata-protocol` `pnpm test`: Test Files 343 passed, 9
skipped (352); Tests 22913 passed, 43 skipped. `typecheck`: exit 0.
- `@objectstack/runtime` `typecheck`: exit 0. Seed files of the runtime
suite (13 files, including `seed-loader.test.ts` and
`seed-org-scoped-references.integration.test.ts`): Tests 141 passed.
- Full `@objectstack/runtime` `pnpm test` at `655dd0d1` (before the
merge): 604 of 605 files passed; the one failure was
`seed-loader.test.ts` "should ignore references to objects not in the
graph", whose fixture `contact` is user-owned and now also carries the
`owner_id` row. Its assertion was updated to name both rows
(`account_id` to `account`, `owner_id` to `sys_user`) in `0a56c258`, and
the file is green at the final head.
- Consumers of `SeedLoaderService` outside these packages, at
`655dd0d1`: objectql seed and publish files (13 files, 227 tests),
`@objectstack/cloud-connection` `marketplace-install-local*` (56 files,
688 tests), `@objectstack/cli` `seed-record-values-load-parity` (1
test): all passed.
## Acceptance notes
- Ruling (card TO) implemented as written: the reference graph treats
the injected owner column like a declared `sys_user` lookup; the pin
serves the as-authored definition; a non-member resolves to NULL with
the "not a member" error, as `rep` does.
- The first-admin handoff (`claimSeedOwnership`) claims rows whose
`owner_id` is NULL; a non-member's row is now NULL, so it is claimable.
Not re-pinned here (outside this file surface); read from
`packages/runtime/src/app-plugin.ts`.
- `content/docs/data-modeling/seed-data.mdx` already promises this (the
target table row for `sys_user`, "people: `owner_id`, people lookups");
its text agrees with the fix, so it is not edited.
- Only `owner_id` is added. The audit `*_by` columns and
`owning_business_unit_id` are also injected lookups but are readonly and
server-stamped; they are not part of this card's ruling and are left as
they were.
- The card's "related observation" (on a walled boot the
organization-create replay runs before the founder's `sys_member` row is
written) is out of scope and untouched.
- Declaration self-check: `Clause-②: no` and `Metadata-protocol: none`
hold. No schema key, accepted value or metadata type moves; a seed that
loaded still loads. A non-member name now lands as NULL with a reported
error instead of as text, which is the behaviour the 18.5.0 changeset
and docs already promised for person references.
## Verification
<details><summary>Red first on origin/main (the card's hypothesis
H1)</summary>
The new pins and the corrected stub, run against the unchanged
`origin/main` loader (`64807a9c`) after a closure build:
- `seed-loader-injected-owner-reference.test.ts`: 3 failed, 8 passed.
`expected [] to deeply equal [ { field: 'owner_id', ... } ]`;
`dependsOn` `['crm_account']` instead of `['crm_account', 'sys_user']`.
- `seed-org-scoped-references.integration.test.ts`: 5 failed, 26 passed.
Single boot: `"owner_id": "Zhang Wei"` stored where `rep` is
`"usr_zhang"`. Walled replay: `"owner_id": "Wang Fang"` and `"Zhang
Wei"` stored as text. The existing #33207 case that seeds `owner_id`
also went red once the stub served the authored definition.
With the fix (`seed-loader.ts` built into `dist/`): 11 of 11 and 31 of
31.
</details>
<details><summary>Ablation (each leg rebuilt; runtime reads
metadata-protocol from dist/)</summary>
Mutation through `scripts/ablation-replace.mjs`: the guard `if
(!resolveInjectedSystemColumns(definition).owner) return fields;`
replaced by `if (definition.fields) return fields;` (anchor 1 to 0, blob
`811047510bd6` to `ccd9579da705`), then `pnpm --filter
@objectstack/metadata-protocol build` and `ablation-dist-preflight.mjs
@objectstack/metadata-protocol
'resolveInjectedSystemColumns(definition).owner' --absent`: marker
absent from all 24 built files. Result: the graph pins 3 failed of 11
and the runtime pins 5 failed of 31, the same cases as on `origin/main`.
Restore: blob back to `811047510bd6` = HEAD, `git diff HEAD` empty, `git
status --porcelain` empty; rebuilt, and the preflight in default mode
reads the marker present in 1 built file. A first attempt that replaced
the call site was refused by the dts build (`TS6133` unused function),
so nothing ran on it.
</details>
<details><summary>Gates</summary>
- `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack
--ran`: 66 derived, 66 run, 0 NOT-MEASURED, 0 UNRUN; every recorded exit
code is 0. `check:query-options-erasure` hit a 300 s local timeout under
a shared box once and passed on rerun; `check:type-check-debt` ran under
the verify lock (re-measure OK, 0 errors above the record).
- PR-body gates with this body as the event: `check-changeset-no-major`
exit 0, `check-closing-keyword-parity` exit 0,
`check-adr-0087-registration` exit 0, `check-empty-changeset` exit 0.
- `dispatch-gates --tier`: no path-derived mandate; 254 changed lines.
- `git merge-tree --write-tree` against `origin/main`: clean. No open PR
touches `seed-loader.ts` or the runtime harness file (59 open PRs read
through REST).
- Full dogfood battery: not owed (no `!` in the title, no `(narrowing)`
arm).
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent fb3d1ff commit 85f2ac5
7 files changed
Lines changed: 242 additions & 12 deletions
File tree
- .changeset
- packages
- metadata-protocol/src
- runtime/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
61 | 66 | | |
62 | | - | |
| 67 | + | |
| 68 | + | |
63 | 69 | | |
64 | 70 | | |
65 | 71 | | |
| |||
| 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 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
61 | 69 | | |
62 | 70 | | |
63 | 71 | | |
| |||
68 | 76 | | |
69 | 77 | | |
70 | 78 | | |
71 | | - | |
| 79 | + | |
72 | 80 | | |
73 | 81 | | |
74 | 82 | | |
| |||
103 | 111 | | |
104 | 112 | | |
105 | 113 | | |
106 | | - | |
| 114 | + | |
107 | 115 | | |
108 | 116 | | |
109 | 117 | | |
| |||
119 | 127 | | |
120 | 128 | | |
121 | 129 | | |
122 | | - | |
| 130 | + | |
123 | 131 | | |
124 | 132 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | | - | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
509 | 511 | | |
510 | 512 | | |
511 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
512 | 542 | | |
513 | 543 | | |
514 | 544 | | |
| |||
1290 | 1320 | | |
1291 | 1321 | | |
1292 | 1322 | | |
1293 | | - | |
| 1323 | + | |
| 1324 | + | |
1294 | 1325 | | |
1295 | 1326 | | |
1296 | 1327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
269 | | - | |
270 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
271 | 275 | | |
272 | 276 | | |
273 | 277 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
177 | 182 | | |
178 | | - | |
179 | | - | |
180 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
181 | 186 | | |
182 | 187 | | |
183 | 188 | | |
| |||
642 | 647 | | |
643 | 648 | | |
644 | 649 | | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
0 commit comments