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

breaking change to custom function now must accept &Option<T> #310

Closed
williamlsh opened this issue Mar 18, 2024 · 3 comments
Closed

breaking change to custom function now must accept &Option<T> #310

williamlsh opened this issue Mar 18, 2024 · 3 comments
Labels

Comments

@williamlsh
Copy link

The latest validator version v0.17.0 doesn't align with the following behavior any more for custom function.

A validation on an Option<_> field will be executed on the contained type if the option is Some.

The custom function must now accept &Option<T> as its argument if it corresponds to the type of a struct field, in contrast to its previous behavior, which only accepted &T even if the actual field type was Option<T>.

@williamlsh williamlsh changed the title breaking change to custom function now must accept Option<T> breaking change to custom function now must accept &Option<T> Mar 18, 2024
@Keats
Copy link
Owner

Keats commented Mar 18, 2024

I thought the previous behaviour was a bug (#303) but I guess it makes more sense to handle Option that way

Keats added a commit that referenced this issue Mar 18, 2024
@chris13524
Copy link

chris13524 commented Mar 18, 2024

I just encountered a need for custom validators to take &Option<T>. Use case is conditionally requiring a field to be defined if and only if another field is set to false (using custom validator args/context for this). If the other field is set to true then the optional field must be None.

Keats added a commit that referenced this issue Mar 18, 2024
@Keats
Copy link
Owner

Keats commented Mar 18, 2024

That sounds like something that should be defined at the schema level. Or make it more like django forms and allow accessing other fields from any field validation function but that's a new feature.

Keats added a commit that referenced this issue Mar 18, 2024
@Keats Keats added the bug label Mar 18, 2024
@Keats Keats closed this as completed in 59a97b3 Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants