jpmckinney / validictory

🎓 deprecated general purpose python data validator
Other
240 stars 57 forks source link

new version not allow a blank True string with format #116

Closed chellychen closed 7 years ago

chellychen commented 7 years ago

hi jamesturk,

I have a problem after update my validictoty lib from 0.8.3 to 1.1.1, while a string is blank, new version will validate format ,like this:

test_blank.py

import validictory

interface_schema = { 'type': 'object', 'properties': { 'ip': {'type': 'string', 'blank': True,'format':'ip-address'}, 'mask': {'type': 'string', 'blank': True,'format':'ip-address'}, }, 'additionalProperties': False }

test_data = {"ip":"","mask":""} validictory.validate(test_data,interface_schema)

it work well in old version,but new version alert Value '' for field '' is not a ip-address

I think the code "if format_validator and value is not None:" can write as 'if format_validator and value is not None and value != "":'

compare: new version: def validate_format(self, x, fieldname, schema, path, format_option=None): ''' Validates the format of primitive data types ''' value = x.get(fieldname, None)

    format_validator = self._format_validators.get(format_option, None)

    if format_validator and value is not None:
        try:
            format_validator(self, fieldname, value, format_option)
        except FieldValidationError as fve:
            if self.fail_fast:
                raise
            else:
                self._errors.append(fve)

old version:

def validate_format(self, x, fieldname, schema, format_option=None): ''' Validates the format of primitive data types ''' value = x.get(fieldname)

    format_validator = self._format_validators.get(format_option, None)

    if format_validator and value:
        format_validator(self, fieldname, value, format_option)

    # TODO: warn about unsupported format ?

would you check this issue? wait for your reply. thank you,best regard.

jamesturk commented 7 years ago

From what I can tell this matches the behavior of other validators- have you tried this w/ any others?

On Tue, Oct 24, 2017 at 4:58 AM, chellychen notifications@github.com wrote:

hi jamesturk,

I have a problem after update my validictoty lib from 0.8.3 to 1.1.1, while a string is blank, new version will validate format ,like this:

test_blank.py

import validictory

interface_schema = { 'type': 'object', 'properties': { 'ip': {'type': 'string', 'blank': True,'format':'ip-address'}, 'mask': {'type': 'string', 'blank': True,'format':'ip-address'}, }, 'additionalProperties': False }

test_data = {"ip":"","mask":""} validictory.validate(test_data,interface_schema)

it work well in old version,but new version alert Value '' for field '' is not a ip-address

I think the code "if format_validator and value is not None:" can write as 'if format_validator and value is not None and value != "":'

compare: new version: def validate_format(self, x, fieldname, schema, path, format_option=None): ''' Validates the format of primitive data types ''' value = x.get(fieldname, None)

format_validator = self._format_validators.get(format_option, None)

if format_validator and value is not None:
    try:
        format_validator(self, fieldname, value, format_option)
    except FieldValidationError as fve:
        if self.fail_fast:
            raise
        else:
            self._errors.append(fve)

old version:

def validate_format(self, x, fieldname, schema, format_option=None): ''' Validates the format of primitive data types ''' value = x.get(fieldname)

format_validator = self._format_validators.get(format_option, None)

if format_validator and value:
    format_validator(self, fieldname, value, format_option)

# TODO: warn about unsupported format ?

would you check this issue? wait for your reply. thank you,best regard.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jamesturk/validictory/issues/116, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAfYt__Fo68o2HzzWh2SYoUWCxASDACks5svaawgaJpZM4QEEiG .

chellychen commented 7 years ago

I have tried jsonschema-2.6.0, but it can't validate blank false and format of ip-address.

before we update validictory, we use the version 0.8.3, it can support ip value is "" while schema is 'blank':' True''format':'ip-adress', and does not alert 'Value '' for field '' is not a ip-address', this is conform our expectation, because we some time don't input ip, and its value is "",we hope it's valid, and some time we input ip, we also hope validate its format.

or if you know some other validators, would you like to tell me, let me see how they validate, if all not support my requirement, I may have to rewrite my code.

thanks .

chellychen commented 7 years ago

and I think if one need always validate ip-address, he can set blank false.

jamesturk commented 7 years ago

depending on your needs I see a few options:

given the pending deprecation of validictory & fact this would be a backwards incompatible change and require a major version # bump I'm going to mark this as closed, but I hope one of the above is acceptable for your needs