You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally wrote as comment in #2913, but this will require more work to fix
While debugging some tests for (#3750), I've begun to think the underlying assumption here is flawed:
...validated against multiple schemas and its parent is a common anyOf validator.
The error messages produced from these cases are usually
very similar and we just take the shortest one.
If there are multiple additional property errors it usually means that the offending element was validated against multiple schemas and its parent is a common anyOf validator.
The error messages produced from these cases are usually
very similar and we just take the shortest one. For example,
the following 3 errors are raised for the `unknown` channel option in
`alt.X("variety", unknown=2)`:
- "Additional properties are not allowed ('unknown' was unexpected)"
- "Additional properties are not allowed ('field', 'unknown' were unexpected)"
- "Additional properties are not allowed ('field', 'type', 'unknown' were unexpected)".
"""
iflen(errors) >1:
# Test if all parent errors are the same anyOf error and only do
# the prioritization in these cases. Can't think of a chart spec where this
# would not be the case but still allow for it below to not break anything.
parent=errors[0].parent
if (
parentisnotNone
andparent.validator=="anyOf"
# Use [1:] as don't have to check for first error as it was used
We're trying to match alt.YValue.
The most helpful thing would be identifying all of the invalid properties.
Naively picking the shortest message is an unfit heuristic.
This can be observed by seeing how the final message changes in an unpredicatble way, simply by adding more invalid properties:
Since (ea647eb) we now at least get YValue included:
>>>some.message"`YValue` has no parameter named 'value'\n\nExisting parameter names are:\nvalue \n\nSee the help for `YValue` to read the full description of these parameters"
The first error
Backtracking to what the message originally looked like from jsonschema.
I think it is pretty clear this is not the error we want:
>>>some._original_message"Additional properties are not allowed ('value' was unexpected)"
Parent message is more useful
Going back one level (.parent) starts to make more sense:
>>>some.parent.message"{'value': 1, 'bin': True, 'aggregate': 'sum'} is not valid under any of the given schemas"
Significant backtracking
It is still possible to undo all of the work from validate_jsonschema
# All errors are then attached as a new attribute to ValidationError so that
# they can be used in SchemaValidationError to craft a more helpful
# error message. Setting a new attribute like this is not ideal as
# it then no longer matches the type ValidationError. It would be better
# to refactor this function to never raise but only return errors.
main_error._all_errors=grouped_errors
ifraise_error:
raisemain_error
else:
returnmain_error
else:
returnNone
I wouldn't want to solve the problem this way, but an example of backtracking to a useful context:
tree_nav= {
err.parent.schema["anyOf"][idx]["$ref"].removeprefix("#/definitions/"): err.messageforidx, errinenumerate(some.parent.context)
}
>>>tree_nav
{'PositionFieldDef': "Additional properties are not allowed ('value' was unexpected)",
'PositionDatumDef': "Additional properties are not allowed ('aggregate', 'bin', 'value' were unexpected)",
'PositionValueDef': "Additional properties are not allowed ('aggregate', 'bin' were unexpected)"}
So the hacky way to do this would be replacing the error we got from 'PositionFieldDef' with the one for 'PositionValueDef'.
For our {'value': 1, 'bin': True, 'aggregate': 'sum'}, we identify the two extra invalid properties "...('aggregate', 'bin' were unexpected)"
What would you like to happen instead?
I think #3750 offers an improvement, but really we need to fix this before raising in validate_jsonschema.
By that stage, we've dropped errors that are better candidates which makes fixing it later much more difficult.
Maybe this would be something to pick up when revisiting #3547, as that PR contains a lot of refactoring/redocumenting in tools.schemapi.schemapi.py
Which version of Altair are you using?
5.6.0dev
The text was updated successfully, but these errors were encountered:
What happened?
Note
Originally wrote as comment in #2913, but this will require more work to fix
While debugging some tests for (#3750), I've begun to think the underlying assumption here is flawed:
schemapi._deduplicate_additional_properties_errors
altair/tools/schemapi/schemapi.py
Lines 452 to 479 in be5e9ec
This assumption conflicts directly with the channel wrappers, since the
"anyOf"
is how they are differentiated.altair/tools/generate_schema_wrapper.py
Line 816 in be5e9ec
Examples
These are all tested against (8fb2661)
We're trying to match
alt.YValue
.The most helpful thing would be identifying all of the invalid properties.
Naively picking the shortest message is an unfit heuristic.
This can be observed by seeing how the final message changes in an unpredicatble way, simply by adding more invalid properties:
Exploring the error tree
Diving into the error tree for
two_err_2
gives us some more clarity:Capturing an error
Spec being validated
altair
transformed messageSince (ea647eb) we now at least get
YValue
included:The first error
Backtracking to what the message originally looked like from
jsonschema
.I think it is pretty clear this is not the error we want:
Parent message is more useful
Going back one level
(.parent
) starts to make more sense:Significant backtracking
It is still possible to undo all of the work from
validate_jsonschema
schemapi.validate_jsonschema
altair/tools/schemapi/schemapi.py
Lines 135 to 170 in be5e9ec
I wouldn't want to solve the problem this way, but an example of backtracking to a useful context:
So the hacky way to do this would be replacing the error we got from
'PositionFieldDef'
with the one for'PositionValueDef'
.For our
{'value': 1, 'bin': True, 'aggregate': 'sum'}
, we identify the two extra invalid properties"...('aggregate', 'bin' were unexpected)"
What would you like to happen instead?
I think #3750 offers an improvement, but really we need to fix this before raising in
validate_jsonschema
.By that stage, we've dropped errors that are better candidates which makes fixing it later much more difficult.
Maybe this would be something to pick up when revisiting #3547, as that PR contains a lot of refactoring/redocumenting in
tools.schemapi.schemapi.py
Which version of Altair are you using?
5.6.0dev
The text was updated successfully, but these errors were encountered: