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

Does voluptuous support multiple field validations #323

Closed
jeff1evesque opened this issue Feb 1, 2018 · 2 comments
Closed

Does voluptuous support multiple field validations #323

jeff1evesque opened this issue Feb 1, 2018 · 2 comments

Comments

@jeff1evesque
Copy link

jeff1evesque commented Feb 1, 2018

Can, I validated 2+ fields at the same time, and receive feedback, on 2+ errors at a given validation instance? The way I've implemented, it seems to catch only the first error. When I fix the first error, then run the voluptuous validation again, the next error is raised, and so forth. Is this generally how validation is implemented either internally with voluptuous, or how the error is caught?

I have the following schema:

            schema = Schema({
                Required('collection'): All(unicode, Length(min=1)),
                Required('model_type'): In(model_type),
                Required('session_type'): 'model_generate',
                Optional('stream'): Any('True', 'False'),
                Required('sv_kernel_type'): In(sv_kernel_type),
                Optional('gamma'): Any(int, float),
                Optional('penalty'): Any(int, float),
            })

If I were to validate my schema:

premodel_settings: {'sv_kernel_type': u'linear', 'stream': 'False', 'session_type': u'model_generate', 'collection': u'collection-1', 'penalty': u'161528', 'model_type': u'svm', 'gamma': u'164'}

As follows:

        try:
            schema(premodel_settings)

        except Exception, error:
            self.list_error.append(error)
            return error

It seems I'm only capturing one error twice:

"expected int for dictionary value @ data['penalty']"

I've commented my exact use case, on an issue, I've just recently quasi finished.

@jeff1evesque
Copy link
Author

Also, thank you for developing and maintaining this project. I was previously using jsonschema, and this seems a little more robust so far.

@jeff1evesque
Copy link
Author

Ah, ok found MultipleInvalid, which will allow multiple keys to be validated.

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

1 participant