Uh oh!
There was an error while loading. Please reload this page.
fix(rest): import dry run must bound-check values, not just coerce them (#3956) - #3996
Merged
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 7 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
Uh oh!
There was an error while loading. Please reload this page.
…em (#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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes#3956.
The problem
The same request body, with only
dryRunflipped, produced two different verdicts. Anumberfield declaringmin: 0received-500: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 acceptance evidence.
Root cause
The dry-run branch in
runImportreturned 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).-500is a perfectly good number.firstMissingRequiredField— required-presence only.Everything the engine's
validateRecordenforces lives past that branch, on the write path only.The fix
ExportFieldMetanow carriesmin/max/minLength/maxLength.buildFieldMetaMapwas dropping them, so the runner could not have checked a bound even if it wanted to.firstConstraintViolationmirrorsvalidateRecord's numeric-range and string-length rules — same type applicability, same comparison, samecodeandmessagetext — so both paths report a violation identically.beforeInserthooks; a pre-hook copy there could reject a row a hook would have made legal. The dry run has no such backstop.Covers all three consumers of the shared runner: the synchronous import route, the async import-job worker, and plugin-auth's user import.
Deliberately not a full mirror
Format checks (email/url/phone), object-level
validationsrules, uniqueness and the state machine still surface only on the real write. Closing those means validating through the engine — avalidateOnlywrite path, whichBatchOptions.validateOnlyalready declares in the spec 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:progressandsummaryare numeric per the spec but unchecked by the engine, and using the wider set would trade the false all-clear for a false alarm.Tests
firstConstraintViolation(bounds both ways, boundary values, absent values, system/readonly skip, unparseable numbers left tocoerceRow, engine-list type applicability).POST /data/:object/importroute, using the issue's exact repro (penalty_amount min: 0, value-500): dry run and real write now agree, field/code/message included;maxLengthbehaves the same; update-mode rows are bound-checked too.packages/restfull suite: 447 passed. The 4 failures inrest.test.ts/rest-env-resolution.test.tsare pre-existing in this worktree (missinglooksLikeInternalErrorLeak/ISecurityServiceexports from stale sibling builds) and reproduce identically with these changes stashed.plugin-authuser-import suite (shares the runner): 26 passed.Pure bug fix — no changeset per AGENTS.md.
🤖 Generated with Claude Code