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

Operation validator should be called AFTER type validation. #18

wants to merge 1 commit into
base: master


None yet
2 participants
Copy link

markon commented Aug 19, 2013

When you implement a new data type, e.g., 'number', you'd expect it to be actually checked before the operations get validated. The test shows that currently you have to modify your method "_validate_min_number" and catch the exception raised by calling int(value), like the following:

def _validate_min_number(self, min_value, field, value):
        """Validates the 'min_number' operation on the 'number' data type."""
            value = int(value)
        except ValueError:
            return super(BaseValidator, self)._validate_min(min_value, field, value)

Otherwise, you`ll get a ValueError, instead of a ValidationError (or whatever).


This comment has been minimized.

Copy link

nicolaiarocci commented Aug 24, 2013


Since validator functions are non-blocking, executing _validate_type before _validate_min_number would not help much (the only blocking exception would be if the type is non-existent).


This comment has been minimized.

Copy link

markon commented Aug 24, 2013

Does it make sense?

This way, when we define a new data type, we have to check again for the 'type' validation in each operation-validator function. It's redundant, while we'd expect it to be already valid in operation-validator functions.

nicolaiarocci added a commit that referenced this pull request Aug 25, 2013

'type' validation is always performed first.
Type validation is performed before any other validation rule which might exist
on the same field (only exception being the 'nullable' rule). In the occurrence
of a type failure, subsequent validation rules on the field will be skipped and
validation will continue on other fields. This allows to safely assume that
field type is correct when other (standard or custom) rules are invoked.

Closes #18.

This comment has been minimized.

Copy link

nicolaiarocci commented Aug 25, 2013


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment