-
Notifications
You must be signed in to change notification settings - Fork 217
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
Error returned by "Any" dict validator should be of the closest alternative #360
Comments
What does "closest" mean? What's the heuristic that you'd use? |
BTW, there's a |
'Closest' - We could define it by the alternative which has the fewest errors, say the smallest list of Yes, but that argument can not reply with validation specific error messages like those provided in the comments to the code above, right? The confusing error message is because it doesn't know which of the Any(..) alternatives you meant. It doesn't know about the field that discriminates between the alternatives (in the example written above, |
Smallest list of errors sounds reasonable. I'd happily accept a PR. I'm not that enthused about a discriminant argument though. |
Before we jump into smallest-list-of-errors, can I make one more case for the discriminant? Here is one of several use-cases we have in Firefox, and you can see that When the schema does not validate, none of those subschemas validate without errors, and Voluptuous must choose which subschema's errors to show. The current approach is I recognize that maybe this is different from what
|
Makes sense. I have no problem with another type such as |
I like |
@ydidwania did you want to pick this project back up? |
I did start with going through the relevant code, but got caught up with
some work.
I will be able to finish this up by the end of November. Will that be ok?
…On Fri, Oct 26, 2018 at 7:44 PM Dustin J. Mitchell ***@***.***> wrote:
@ydidwania <https://github.com/ydidwania> did you want to pick this
project back up?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#360 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AVzU-VuuB9njrae3Hi-lmX6z0cExJiroks5uoxitgaJpZM4WieoJ>
.
|
Sounds good! |
Validation of
Any(..)
is done in the order in which the alternatives are written. When using dicts, if none of them match, the deepesterror
is returned. Theerror
(that is returned in the end) is updated only when it is more nested in an alternate dict than the already existing error.If all dicts are of the same level, the error is from the first dict in
Any(..)
. It would be better if Any() is made to return the error of the closest alternative. Or provide adiscriminant
function in the parameters used to generate error messages.For the example below the validation error for all three types is at the same level of the dict. The error for type A is returned as that is the first to be validated.
Probably, the error best suited here is
Maybe we could return the one with shortest
errors
list (https://github.com/alecthomas/voluptuous/blob/master/voluptuous/schema_builder.py#L536) among all alternatives.Original discussion on BMO (reported by @djmitche)
The text was updated successfully, but these errors were encountered: