You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6844e6b
Browse filesBrowse the repository at this point in the historyBrowse files
fix(objectql): a following amount whose parent code field is no longer served is refused with a message that says so (#34024)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbTGhxJSYAmQXU7efVdNqrpw)_Fixes#33888
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:子表金额跟随父记录币种、而父对象已不再提供该币种字段(提供它的扩展包被停用或卸载)时,写入仍以
`ERR_CURRENCY_CODE_REQUIRED` / 400
拒绝,但提示改为说明"父对象不再提供该字段",并在注册表仍记得时点名被停用的包。
- 为什么改:旧提示说"父记录币种为空,请先写入币种",而那个字段已经不存在,照做只会得到另一个错误。
- 风险与回滚:只改提示文案;错误码、状态码、`field`、`amountField` 不变,币种字段确实为空时的原文案一字不变。回滚即还原本
PR。
- 先看:`packages/objectql/src/validation/record-currency-code.ts` 的
`parentCodeFieldServingOf` 与 `codeRequiredMessage` 新分支;再看
`record-currency-guards.test.ts` 末尾新增的 describe。
- 两分钟验证:`pnpm --filter @objectstack/objectql exec vitest run --project
local src/record-currency-guards.test.ts -t "no longer served"`,预期 2
个用例通过。
- 需要你做的:无,席位落地。
## What changes
`RecordCurrencyCodeRequiredError` gains a third case for a following
amount (`currencyField: 'MASTER_DETAIL.CODE'`): the parent object, as
served at the write, declares no field under the code segment. Before,
that case fell into the blank-code text, which asks for a code to be
written into the field that is not there. Now the refusal reads, for the
measured disable path:
> Insert on 'suite_line' was REFUSED: 'amount' holds an amount in its
parent record's currency (currencyMode: 'record', following
'invoice.currency_code' through the master_detail 'invoice'), and
'suite_invoice' does not serve a field 'currency_code' (the package
'com.test.supplier' that contributed it is disabled); the amount has no
code to follow until that field is served again, or leave 'amount'
empty. The row was not written.
- **Package clause.** The registry keeps a disabled package's `extend`
contribution, so on the disable path the package is named. An uninstall
removes the contribution, so there the clause is the card's generic one:
"(a package that contributed it may be disabled or uninstalled)".
- **Where the fact comes from.** The path pair is resolved in
`recordCurrencyPairs` / `recordCurrencyPathOf` from the child's own
field map only, so the guard cannot know what the parent serves.
`assertRecordCurrencyCodes` takes one new optional argument, a
`ParentCodeFieldServing` reader. `parentCodeFieldServingOf(registry)`
builds it from `getObject` (the served fold, a disabled extension left
out), `getObjectContributors` and `isPackageDisabled`. The four
write-side callers pass it: insert, by-id update, predicate update and
the `validate()` preview, in `engine-insert.ts`, `engine-update.ts` (two
sites) and `engine-validate.ts`. It is asked only after a pair is
refused, about the first refused pair, so the accepted write path reads
nothing new.
- **Unchanged.** `ERR_CURRENCY_CODE_REQUIRED` / 400, `field`, `fields`,
`amountField`, and the full text for a served code field that is blank.
A parent object that is not served at all keeps today's text. The guard
is not exported from the package entry, so the published API surface
does not move.
## Tests
`packages/objectql/src/record-currency-guards.test.ts` (the shared
harness for this guard) gains one top-level describe on the measured
fixture: `billing` owns `suite_invoice` and `suite_line`, `supplier`
extends `suite_invoice` with `currency_code`, `suite_line.amount`
follows `invoice.currency_code`.
- disable path: after `disablePackage(supplier)` a child insert is
refused `ERR_CURRENCY_CODE_REQUIRED` / 400 with `field`
`invoice.currency_code`, the message carries the not-served clause
naming the disabled package, and does not carry "has a blank". The same
test then uninstalls the supplier and asserts the generic package
clause.
- CONTROL: under a served but blank parent code, the message equals
today's full text.
Ablation (committed fix first, mutation through
`scripts/ablation-replace.mjs`, which restored the blob to HEAD and
found `git diff HEAD` empty): replacing the reader call
`parentCodeServing?.(path.master, path.code)` with `undefined` turns the
disable-path test red and leaves the blank-text CONTROL green.
## Acceptance notes
- `Clause-②: no` confirmed against the ADR-0112 ledger row for
`ERR_CURRENCY_CODE_REQUIRED`
(`packages/spec/src/api/error-code-ledger.zod.ts`): it records the code
and status, not the text.
- The lifecycle doors' own behaviour stays parked on #33628 (seat ruling
D). This PR changes only what the write's refusal says.
## Verification
Readings at head `d50cea4559` (branch merged with `origin/main` at
`0ac112fcd`), each command under `scripts/pm/os-verify-lock.sh` where it
builds or tests:
- `pnpm --filter @objectstack/objectql typecheck`: tsc clean;
`check:test-typecheck: OK` (39 files / 233 errors / 64 pinned signatures
held, unchanged).
- `pnpm --filter @objectstack/objectql exec vitest run --project local
--maxWorkers=2`: VERDICT command-exit 0, Test Files 598 passed (598),
Tests 13235 passed (13235).
- `record-currency-guards.test.ts` alone: 73 passed (73), the two new
tests included.
- Derived gate families (`node scripts/pm/dispatch-gates.mjs
--commands`, 68 families at `d50cea4559`): 66 run locally, every one
exit 0. `check:dual-build-cjs-loads` is left to CI;
`check:type-check-debt` runs under the lock and its reading is in the
report comment on #33888.
- `eslint --no-inline-config` on the five touched source files: exit 0.
`check-nul-bytes`: OK.
- `test:repo` is not run locally: the diff changes no repo-project test
and the derivation names none; CI's `Test Core` runs it.
<details><summary>Ablation output (disable-path test, mutation landed
and restored)</summary>
```text
ablation-replace: ok mutation landed: anchor 1 -> 0, blob c74cd8b -> f833530689a9
× disable: the supplier disabled, a line with an amount is refused naming the field as not served and the disabled package
Tests 1 failed | 1 passed | 71 skipped (73)
Received: "... and the 'suite_invoice' record it names has a blank 'currency_code', or it names none. The row was not written. Write the parent's ISO 4217 code (for example 'USD') into 'suite_invoice.currency_code' first ..."
ablation-replace: ok restored: blob == HEAD (c74cd8b) and `git diff HEAD` is empty
```
</details>
Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(objectql): a following amount whose parent code field is no longer served is refused with a message that says so
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
A `record`-mode amount that follows its parent's currency (`currencyField: 'MASTER_DETAIL.CODE'`) is still refused `ERR_CURRENCY_CODE_REQUIRED` / 400 when the parent object, as served at the write, no longer declares the code field (the package that contributed it was disabled or uninstalled). The message used to say the parent's code was blank and asked for a code to be written into that field, which is not there. It now says the parent does not serve the field, names the disabled package when the registry still holds its contribution, and says the amount has no code to follow until the field is served again, or that the amount can be left empty. The code, status, `field` and `amountField` are unchanged, and so is the message for a served code field that is blank.
0 commit comments