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
fix(rest): import dry run must bound-check values, not just coerce them (#3956)
The same request body, with only `dryRun` flipped, produced two different
verdicts. A `number` field declaring `min: 0` received `-500`: the dry run
answered `ok:1, errors:0, created:1` — the Console wizard renders that as
「全部 1 行均有效」 — and the real write then answered `ok:0, errors:1,
penalty_amount must be ≥ 0`, dropping the row. A pre-check that cannot
predict the write is worse than no pre-check: it turns "your file has a
problem" into a false all-clear, and reviewers can't use it as evidence.
The dry-run branch in `runImport` returned before any field-constraint
check ran. Only two gates stood in front of it, and neither looks at a
declared bound:
- `coerceRow` — pure value conversion (is this cell a number at all,
does this select option exist, does this lookup resolve). `-500` is a
perfectly good number, so it sailed through.
- `firstMissingRequiredField` — required-presence only.
Everything the engine's `validateRecord` enforces (numeric range, string
length, formats) lives past that branch, on the write path only.
This closes the range/length half:
- `ExportFieldMeta` now carries `min` / `max` / `minLength` /
`maxLength`. The projection built by `buildFieldMetaMap` was dropping
them, so the runner could not have checked a bound even if it wanted
to.
- `firstConstraintViolation` mirrors `validateRecord`'s numeric-range
and string-length rules — same type applicability, same comparison,
same `code` and `message` text — so both paths now report a violation
identically.
- The runner consults it on the DRY RUN ONLY. The write path already
has the engine's own validation, which runs AFTER beforeInsert hooks;
a pre-hook copy there could reject a row a hook would have made
legal. The dry run has no such backstop.
Deliberately not a full mirror. Format checks (email/url/phone),
object-level `validations` rules, uniqueness and the state machine still
surface only on the real write — closing those means validating through
the engine (a `validateOnly` write path, which `BatchOptions.validateOnly`
already declares but nothing implements) rather than growing this copy.
The bounded-type lists are the engine's own, not the spec's wider
`NUMERIC_VALUE_TYPES` / `STRING_VALUE_TYPES`: `progress` and `summary`
are numeric per the spec but unchecked by the engine, and using the wider
set would trade the false all-clear for a false alarm.
Covers all three consumers of the shared runner: the synchronous import
route, the async import-job worker, and plugin-auth's user import.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
0 commit comments