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

ErrorTree assumes one error per validator #442

Open
Julian opened this issue Aug 3, 2018 · 4 comments
Open

ErrorTree assumes one error per validator #442

Julian opened this issue Aug 3, 2018 · 4 comments
Labels
Bug Something doesn't work the way it should. Error Reporting Issues related to clearer or more robust validation error reporting

Comments

@Julian
Copy link
Member

Julian commented Aug 3, 2018

This seems like a correct assumption (both at the minute and likely forever, which probably should be better documented) but if it ever were not the case, it'd silently not do nice things, which is not very nice.

EDIT: it's not the case

@Julian Julian added the Bug Something doesn't work the way it should. label Aug 13, 2018
@ThrowsException
Copy link

I think I ran into this today with this.

schema = {
    "type": "object",
    "properties": {
        "accounts": {
            "type": "array",
            "minItems": 1,
            "items": {"$ref": "#/components/schemas/Account"}
        }
    },
    "components": {
        "schemas": {
            "Account": {
                "properties": {
                    "first_name": {"type": "string"},
                    "last_name": {"type": "string"}
                },
                "required": ["first_name", "last_name"]
            }
        }
    },
}

v = Draft7Validator(schema)
item = {"accounts": [{"foo": 123, "bar": True}]}

l = [err for err in v.iter_errors(item)]
error_tree = ErrorTree(v.iter_errors(item))

# prints 2 - first_name and last_name are missing
print(len(l))

# print 1 - the last ValidationError object to be assigned at the level accounts,0 wins.
print(error_tree.total_errors)

this happens because when creating the error tree container, the path deque('accounts', 0) will happen twice in my case both for the required validator and the last one in will get its error assigned. https://github.com/Julian/jsonschema/blob/14710c64f2df383e00366b2db839f40ae0d691c8/jsonschema/exceptions.py#L217-L223

Would checking to see if an error already exists at the level and appending another ValidationError object be possible?

Julian added a commit that referenced this issue Nov 17, 2020
3627cc11 Fix draft3 as well, which didn't have allOf.
eb1618b5 Fix misspelled reference in infinite-loop-detection tests
d7821b62 remove duplicate files added by mistake in PR#446
a27c949b Merge pull request #446 from json-schema-org/ether/infinite-loop-detection
371fcaba Add a test to demonstrate the invalidity of a naive infinite loop detection algorithm
45436c6c Add a test to demonstrate the invalidity of a naive infinite loop detection algorithm
14cfcde1 Merge pull request #445 from json-schema-org/ether/naive-ref-replacement
128146da test that literal $refs are not evaluated as keywords
71ba357b Merge pull request #442 from jimblackler/master
a6f759aa Update README.md
0f35b324 Merge pull request #441 from plxel/patch-1
d36b8b97 Update README.md
d657d2b8 Update index.js
6a925b8d change folder to baseUriChange

git-subtree-dir: json
git-subtree-split: 3627cc1178c0ff03d2e3eacf4162d32091d21763
@TheFirstMe
Copy link

TheFirstMe commented Aug 9, 2021

@Julian Any updates on this issue?

I have this schema and instance:

schema = {
    "title": "title",
    "type": "object",
    "additionalProperties": False,
    "properties": {
        "date_filter": {
            "type": "object",
            "additionalProperties": False,
            "properties": {
                "from": {
                    "type": "string",
                    "format": "date-time"
                },
                "to": {
                    "type": ["string", "null"],
                    "format": "date-time"
                }
            },
            "required": ["from", "to"]
        }
    }
}

instance = {
    "date_filter": {},
    "test_field": 1
}

The ValidationError for "from" is missing.

@Julian
Copy link
Member Author

Julian commented Aug 9, 2021

Not if the ticket is still open, but I'm more than happy to review a proposed change (or design)!

@Julian Julian added the Error Reporting Issues related to clearer or more robust validation error reporting label Aug 19, 2022
@flying-sheep
Copy link

flying-sheep commented Oct 25, 2022

The stdlib’s email.message.EmailMessage class works like a dict but has a .get_all(key) method.

If you use a similar multidict class to back ErrorTree, you can also make .items() and .values() yield multiple errors for the same key.

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

No branches or pull requests

4 participants