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

Custom error message instead of "xx is a required property" #691

Closed
cpj001 opened this issue May 25, 2020 · 1 comment
Closed

Custom error message instead of "xx is a required property" #691

cpj001 opened this issue May 25, 2020 · 1 comment

Comments

@cpj001
Copy link

cpj001 commented May 25, 2020

# This is my schema
schema = {
    "type": "object",
    "properties": {
        "pid": {"type": "integer", "error": (4001, "pid error")},
        "email": {"type": "string", "error": (4002, "email error")},
        ...
    },
    "required": ["pid", "email",  ...]
}


# This is how I process the errors
my_data = {
    "pid": 1,
    "email": "test@test.com"
}
v = Draft7Validator(schema)
err_list = []
for error in v.iter_errors(my_data):
    err_list.append(error.schema["error"])
print(err_list)

My requirement is to get all validation errors, so I used iter_errors to get them.
But I only can retrieve the error field that I defined myself when the pid has data but the wrong type. I can not get the custom error field if I don't post pid in my_data.

Does anyone know the resolution? (I must add the custom error message for every field)

@Julian
Copy link
Member

Julian commented Jun 3, 2020

Hi. This sounds like a duplicate of #119. Please have a look there, and certainly a PR is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants