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

Mitigate undesired side effect of new best_match behaviour with alternative proposal #1257

Open
ilia1243 opened this issue May 15, 2024 · 1 comment · May be fixed by #1258
Open

Mitigate undesired side effect of new best_match behaviour with alternative proposal #1257

ilia1243 opened this issue May 15, 2024 · 1 comment · May be fixed by #1258
Labels
Bug Something doesn't work the way it should. Error Reporting Issues related to clearer or more robust validation error reporting

Comments

@ilia1243
Copy link

ilia1243 commented May 15, 2024

In continuation to #1250. The fix has seemingly undesired side effect.

from jsonschema import Draft202012Validator as Validator, exceptions

schema = {'oneOf': [
    {'properties': {'run': {'type': 'string'}}, 'required': ['run']},
    {'properties': {'uses': {'type': 'string'}}, 'required': ['uses']},
]}
instance = {'uses': 1, 'run': 1}

error = exceptions.best_match(Validator(schema).iter_errors(instance))
print(schema, "\n\n", error)

After the fix it produces:

 1 is not of type 'string'
On instance['run']:
    1

Conceptually, it is not clear why run has priority (I understand that technically it has priority due to the alphabetical order).

Based on real example https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/github-workflow.json

As an alternative proposal, the relevance function could not be changed, but best_match could distinguish errors having different error.path in the same subscheme, and choose first of them (maybe having even not the minimal relevance, but the maximum one for this particular subscheme provided that it is still minimal among different subschemes).

@Julian Julian added Bug Something doesn't work the way it should. Error Reporting Issues related to clearer or more robust validation error reporting labels May 15, 2024
@ilia1243
Copy link
Author

Opened pull request with possible improvement of best_match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something doesn't work the way it should. Error Reporting Issues related to clearer or more robust validation error reporting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants