Skip to content
This repository was archived by the owner on Feb 28, 2026. It is now read-only.
This repository was archived by the owner on Feb 28, 2026. It is now read-only.

The correspondence between error messages and validation logic is inconsistent #191

Description

@zhoxing-ms

The verification logic is as follows:

# in msrest.serialization
validation = {
"min_length": lambda x, y: len(x) < y,
"max_length": lambda x, y: len(x) > y,
"minimum": lambda x, y: x < y,
"maximum": lambda x, y: x > y,
"minimum_ex": lambda x, y: x <= y,
"maximum_ex": lambda x, y: x >= y,
"min_items": lambda x, y: len(x) < y,
"max_items": lambda x, y: len(x) > y,
"pattern": lambda x, y: not re.match(y, x, re.UNICODE),
"unique": lambda x, y: len(x) != len(set(x)),
"multiple": lambda x, y: x % y != 0
}
# in msrest.serialization # def validate(cls, data, name, **kwargs)
for key, value in kwargs.items():
validator = cls.validation.get(key, lambda x, y: False)
if validator(data, value):
raise ValidationError(key, name, value)

The error message is as follows:

# in msrest.exceptions
_messages = {
"min_length": "must have length greater than {!r}.",
"max_length": "must have length less than {!r}.",
"minimum": "must be greater than {!r}.",
"maximum": "must be less than {!r}.",
"minimum_ex": "must be equal to or greater than {!r}.",
"maximum_ex": "must be equal to or less than {!r}.",
"min_items": "must contain at least {!r} items.",
"max_items": "must contain at most {!r} items.",
"pattern": "must conform to the following pattern: {!r}.",
"unique": "must contain only unique items.",
"multiple": "must be a multiple of {!r}.",
"required": "can not be None.",
"type": "must be of type {!r}"
}

The correspondence between error messages and validation logic is inconsistent.
Take two examples:

  1. minimum
    When validator(data,value) fails to pass the verification of lambda x, y: x < y, the error message is must be greater than {value}., but actually data can be equal to value.
  2. minimum_ex
    When validator(data,value) fails to pass the verification of lambda x, y: x <= y, the error message is must be equal to or greater than {value}., but actually data can not be equal to value.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions