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

Operation validator should be called AFTER type validation. #18

Closed
wants to merge 1 commit into from

Conversation

@markon
Copy link

@markon 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."""
        try:
            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).

@nicolaiarocci
Copy link
Member

@nicolaiarocci nicolaiarocci commented Aug 24, 2013

Hello,

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).

@markon
Copy link
Author

@markon 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 issue Aug 25, 2013
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.
@nicolaiarocci
Copy link
Member

@nicolaiarocci nicolaiarocci commented Aug 25, 2013

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants