fix(pinia-orm): apply casts before field type validation on save#2029
Merged
Conversation
Casts for the 'set' operation ran after $fillField, so the type check warned about the raw input value (e.g. 'Field notes:organization_id - 10191 is not a number') even though the cast converts it right after. The cast now runs before the field is filled, so validation sees the casted value. Values filled from the attribute default still pass through the cast afterwards, as before. fixes #2003
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2029 +/- ##
==========================================
- Coverage 99.43% 99.40% -0.04%
==========================================
Files 82 82
Lines 3022 3025 +3
Branches 530 533 +3
==========================================
+ Hits 3005 3007 +2
- Misses 14 15 +1
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Jul 19, 2026
Merged
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.
Bug
When saving, casts for the
setoperation were applied after$fillField(). The attribute type check therefore validated the raw input and logged spurious warnings likeeven though the cast (e.g.
NumberCast) converts the value immediately afterwards and the store ends up with the correct value (#2003).Fix
Apply the cast before the field is filled, so type validation sees the casted value. Values that fall back to the attribute default (input
undefined) still pass through the cast after filling — unchanged behavior. Side effect worth noting: when a field has both a set-mutator and a cast, the mutator now receives the casted value (cast → mutate instead of mutate-after-cast) — this mirrors the get path (mutate → cast) symmetrically.Tests
New regression test:
@Cast(() => NumberCast) @Num(null)field saved with a string value must not warn and must store the number. Fails before, passes after. Full suite green (402 tests).fixes #2003