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

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

Open
jason-s opened this issue Jan 6, 2015 · 5 comments
Labels
Bug Something doesn't work the way it should. Error Reporting Issues related to clearer or more robust validation error reporting Help Wanted An enhancement or bug for which a pull request is welcomed and which should have a clear definition.

Comments

@jason-s
Copy link

jason-s commented Jan 6, 2015

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.

@jason-s
Copy link
Author

jason-s commented Jan 6, 2015

It also doesn't look like there is any reliable way to get the full path of the element causing the problem; this should be /debug/foo/bar/44hoho, and I can get the /debug/foo/bar part from the relative_path attribute, but 44hoho is buried in the text of the message attribute, and not available elsewhere (e.g. in cause or something).

@Julian
Copy link
Member

Julian commented Jan 21, 2015

Sorry, I thought I replied here, but yeah the first thing certainly doesn't look right. Any chance you might have hunted down where the problem is?

The second thing (getting the full path to your problem) is likely another instance of #119.

@Julian Julian added the Bug Something doesn't work the way it should. label Jan 21, 2015
@jason-s
Copy link
Author

jason-s commented Jan 21, 2015

Any chance you might have hunted down where the problem is?

nope, sorry.

@samarsault
Copy link

@jason-s, what is the desired output ?

@jason-s
Copy link
Author

jason-s commented Feb 26, 2015

Since the schema is

{'additionalProperties': False, 'type': 'object', 'patternProperties': {'^[^\\d\\W]\\w*$': {'type': 'string'}}}

the relative_schema_path (and schema_path) should be

deque(['properties', 'debug', 'properties', 'foo', 'properties', 'bar'])

and not

deque(['properties', 'debug', 'properties', 'foo', 'properties', 'bar', 'additionalProperties'])

The point is that if I take the schema path and find the value located there, it should be consistent with what schema refers to.

As for my desired output, I want something that points me to /debug/foo/bar/44hoho. I get /debug/foo/bar from the path property, I'm missing the 44hoho part.

Julian added a commit that referenced this issue Nov 5, 2017
9567c58 Merge pull request #189 from blackivory86/uri_formats
1066f7f Merge pull request #192 from furstenheim/master
0b71ddd Update README.md
82db537 Merge pull request #191 from korzio/master
1aecb7b feat(const): Add validation tests for arrays
b9d4dbd set unique descriptions for test-cases
aaa3ef7 adds more valid and invalid URI testcases
728066f Merge pull request #188 from json-schema-org/sequences-and-objects
c47341a Flesh out some more ignore cases for object validators.
f339360 make test descriptions unique and no longer than 60 chars
6820a83 Merge branch 'CroniD-master'
aaa32d8 test: update "json-pointer" format to exclude fragments
85a552f added some more tests for json-pointer format
b7b79fc extended tests for json-pointer format

git-subtree-dir: json
git-subtree-split: 9567c588bc9d1705b4840ee9d9f3f268f40c1e68
@Julian Julian added the Help Wanted An enhancement or bug for which a pull request is welcomed and which should have a clear definition. label Oct 16, 2021
@Julian Julian added the Error Reporting Issues related to clearer or more robust validation error reporting label Aug 19, 2022
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 Help Wanted An enhancement or bug for which a pull request is welcomed and which should have a clear definition.
Projects
None yet
Development

No branches or pull requests

3 participants