Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potentially breaking: Make null validation errors consistent across schema #1982

Merged
merged 2 commits into from
Apr 14, 2023

Conversation

jquense
Copy link
Owner

@jquense jquense commented Apr 14, 2023

Previously, schema that parse to invalid values like InvalidDate or NaN always tripped the typeError validation before the nullability error. This was the due to typeError no longer firing on null values, with the expectation that it would always hit the newer nullability check.

This change fixes the issue for Number and Date schema, so that they act the same as String and other schema, where null values do not trigger the typeError validation. The consequence of this is that casting null values for non-nullable number schema, now return null instead of NaN and dates, return null instead of InvalidDate. Essentially these schema will not fruitlessly attempt to coerce null into a number or date anymore.

I am marking this as a bug fix since it is, and as with most bug fixes, could also be considered a breaking change. I'm going to optimistically not cut a v2 for this. If you have unexpected changes it is likely due to number/date schema hitting different validation errors (nullability).

Previously for these schema it was common practice to change the typeError for these schema to something like "this is required"assuming the issue was due to invalid nulls. NOW the schema will show the locale.notNull message, so if you may want to adjust that to something more user friendly if you surface default locale messages to users (we don't generally recommend that).

@jquense
Copy link
Owner Author

jquense commented Apr 14, 2023

fixes @jarnaiz issue in #1952

@jquense jquense merged commit f999497 into master Apr 14, 2023
@jquense jquense deleted the null-checks branch April 14, 2023 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant