Skip to content

ValidationError when a value is equal to minimum or maximum value specified in schema #4

@lukemorrill

Description

@lukemorrill

I have a schema with entries such as this:

{ "name": "my_var", "description": "Test variable, "type": "integer", "minimum": 0, "required": true },

But when I provide data with the above field set to a value of "0", I get this validation error:

`
self = <pycsvschema.checker.Validator object at 0x11ea71f10>

def validate(self):
    with open(self.csvfile, "r") as csvfile:
        csv_reader = csv.reader(csvfile, **self.csv_pars)

        # Read first line as header
        self.header = next(csv_reader)
        self.prepare_field_schema()

        with utilities.file_writer(self.output) as output:
            # Concat errors from header checking and row checking
            for error in chain(self.check_header(), self.check_rows(csv_reader)):
                if self.errors == "raise":
                  raise error

E pycsvschema.exceptions.ValidationError: <ValidationError: 'Value 0 is less than minimum of 0'; column: my_var; row: 2>
`

This occurs for both integers and numbers, and for minimum as well as maximum constraints. If I explicitly set exclusiveMinimum or exclusiveMaximum to false, it still occurs. However, if I set either of them to true then the behavior does not occur for the particular constraint. I believe this behavior is the opposite of what is intended.

Looking at the code in row_validators.py:

`

if exclusiveminimum:
    failed = minimum > cell['value']
    comapre = "less than or equal to"
else:
    failed = minimum >= cell['value']
    comapre = "less than"

`

I think the ">" and ">=" need to be swapped. I can make the changes and submit a pull request if this seems right to you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions