fix(objectql): enforce array shape for multi-value fields in the write pipeline#2553
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 14 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
…e pipeline (#2552) A lone scalar sent at a multiselect / checkboxes / tags / select+multiple / lookup+multiple field used to pass validation and reach the driver verbatim (PATCH {"labels":"frontend"} → 200, stored as a string), silently corrupting the column shape for every array-consumer. select+multiple was worse: a legal ARRAY was stringified to "a,b" and mis-rejected as invalid_option, while lookup+multiple had no shape check at all. - normalizeMultiValueFields(): wrap unambiguous scalars (string/number/boolean) into single-element arrays, in place, before validation — called at all four validateRecord sites in engine insert/update (covers REST, engine callers, and SeedLoader, which all funnel through them) - validateOne(): multi-value fields must be arrays; anything un-wrappable (plain objects, nested junk) is rejected with a new `invalid_type` code instead of hitting storage - select/radio + multiple:true now routes through the multi-value branch with per-element option validation Closes #2552 Co-Authored-By: Claude <noreply@anthropic.com>
68 tasks
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 free
to 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 #2552
Problem (scanned from source, verified via REST e2e)
The write pipeline stored a lone scalar sent at a multi-value field verbatim —
PATCH { labels: "frontend" }at amultiselectreturned 200 and the column read back as a string, silently corrupting the array shape for every consumer. Found via the console bulk-edit dialog (pre-#2186 objectui sent scalars for multi params), but the server-side hole accepts it from ANY client.Worse,
select+multiplemis-rejected legal arrays: the single-select validation branch (record-validator.ts) stringified["a","b"]to"a,b"and threwinvalid_option.Scan also confirmed the runtime expands
Field.usertotype: 'user'(NOT'lookup') — e2e against the showcaseteam_membersfield caught that a lookup-only type set missed it. Perpackages/spec/src/data/field.zod.ts:377,multipleapplies to select/lookup/file/image, anduseris stored identically tolookup.Fix (
@objectstack/objectql)normalizeMultiValueFields(new, called at all 4 validateRecord call-sites inengine.ts): coerces unambiguous scalars (string/number/boolean) into single-element arrays IN PLACE before validation, formultiselect/checkboxes/tagsandselect/radio/lookup/user/file/imagewithmultiple: true.validateRecord: multi-value fields must now be arrays — anything un-wrappable (plain objects, junk) is rejected with a newinvalid_typecode instead of hitting storage. Array elements are still validated againstoptions; reference/attachment types skip options (integrity handled elsewhere).select/radiobranch now guarded withmultiple !== true, fixing the legal-array mis-rejection.Tests
record-validator.test.ts— normalization, shape rejection, element option checks, single-select non-regression (incl.user/filetypes).engine-multivalue-normalize.test.ts(new) — asserts on what the driver receives across insert/update for all covered types.@objectstack/objectqlsuite: 59 files / 737 tests pass.PATCH {"team_members":"<uid>"}at auser+multiplefield → stored as["<uid>"]✅400 invalid_type✅400 invalid_option✅🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com