Skip to content

error object properties "schema" and "relative_schema_path" seem to be inconsistent #191

Open
@jason-s

Description

@jason-s

I need to parse a jsonschema.exceptions.ValidationError object to help produce a more useful error message to my customers, but I am not sure that the fields of the ValidationError object are correct.

Test case: https://gist.github.com/jason-s/6d2b3418f4edb7fc8064

Raw object (in yaml format, but jsonschema is representation-agnostic -- thank you, it means I can use it for yaml files):

debug:
  foo:
    bar:
      jiminy: cricket
      mickey: mouse
      44hoho: twinkie

The validator correctly find that 44hoho is not a legal property name; it doesn't match patternProperties and in my schema I have additionalProperties = false.

The problem is that the error object's relative_schema_path and schema seem inconsistent.

My test case prints:

parent         : None
relative_path  : deque(['debug', 'foo', 'bar'])
relative_schema_path: deque(['properties', 'debug', 'properties', 'foo', 'properties', 'bar', 'additionalProperties'])
instance       : {'jiminy': 'cricket', 'mickey': 'mouse', '44hoho': 'twinkie'}
schema_path    : deque(['properties', 'debug', 'properties', 'foo', 'properties', 'bar', 'additionalProperties'])
validator      : additionalProperties
context        : []
path           : deque(['debug', 'foo', 'bar'])
message        : Additional properties are not allowed ('44hoho' was unexpected)
schema         : {'additionalProperties': False, 'type': 'object', 'patternProperties': {'^[^\\d\\W]\\w*$': {'type': 'string'}}}
cause          : None
validator_value: False

Note that the schema attribute is a sub-portion of the schema object, but the relative schema path is from the root schema.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething doesn't work the way it should.Error ReportingIssues related to clearer or more robust validation error reportingHelp WantedAn enhancement or bug for which a pull request is welcomed and which should have a clear definition.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions