superRefine is not called on a derived schema #4023
Unanswered
Benoit-ROBIN
asked this question in
Q&A
Replies: 1 comment
-
btw, There is a superRefine in the source schema, and it's always called when I use it on the partial validation. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Why doesn't superRefine apply if the base schema throws an error?
I'm encountering an issue where superRefine does not execute when the base schema already throws an error.
Some context
createStrictSchema
takes an existing schema and removes the optional method when a describe method has a specific value.Why?
My app has a form to update what we call an "Operation." The update can be partial, but if a value is provided, it must be valid. For example, if we expect a number between 0 and 10, an error is thrown if the value does not meet this rule.
I need a second schema derived from the first one to validate the final form, and for that, I have to remove the optional methods from certain fields.
I don’t want to maintain two separate schemas, which is why I created this helper.
Expected Behavior
I expect that superRefine should always be executed, even if the base schema has already failed validation.
However, it seems that if an error occurs in the base schema (e.g., due to makeRequired making a previously optional field required), superRefine does not run.
Observed Behavior
When the base schema throws a validation error, the superRefine function is skipped entirely.
This means that any additional validation logic within superRefine never executes if the base schema fails first.
Questions:
Is this the expected behavior of superRefine?
If so, is there a recommended way to ensure that superRefine always runs, regardless of whether the base schema fails?
Thanks in advance for your insights! 🚀
Beta Was this translation helpful? Give feedback.
All reactions