#34503 closed Bug (invalid)

Missleading message in MinValueValidator and MaxValueValidator

Reported by: bartektrybala Owned by: nobody
Component: Core (Serialization) Version: 4.2
Severity: Normal Keywords: MaxValueValidator, MinValueValidator, message, less or equal
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Here is a message error for MaxValueValidator:
message = _("Ensure this value is less than or equal to %(limit_value)s.")

but compare method checks if a < b. So it's not accurate comparision or message, It should checks a <= b, isn't it?
The same for MinValueValidator

Change History (2)

comment:1 by bartektrybala, 17 months ago

Easy pickings: set

comment:2 by David Sanders, 17 months ago

Resolution: invalid
Status: newclosed

Sorry I think you may have misread the code.

Here is MaxValueValidator:

class MaxValueValidator(BaseValidator):
    message = _("Ensure this value is less than or equal to %(limit_value)s.")
    code = "max_value"

    def compare(self, a, b):
        return a > b

Here a is the cleaned value while b is the limit. If compare is True then a ValidationError is raised. The inverse of this comparison is therefore correct: cleaned value must be less than or equal to the limit.

Note: See TracTickets for help on using tickets.
Back to Top