Opened 27 hours ago
Closed 25 hours ago
#36019 closed Bug (duplicate)
MinValueValidator and MaxValueValidator messages do not match compare operators
Reported by: | Samuel Nussbaumer | Owned by: | |
---|---|---|---|
Component: | Core (Other) | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Samuel Nussbaumer | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | yes |
Description
Excerpt from /django/core/validators.py:
@deconstructible 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 @deconstructible class MinValueValidator(BaseValidator): message = _("Ensure this value is **greater than or equal** to %(limit_value)s.") code = "min_value" def compare(self, a, b): return a < b
The messages imply that the comparison between a and b would be a <= b or a >= b whereas in practice they only check if a is greater or lesser than b.
Reprod:
- Define a form field with validators=[MaxValueValidator(3), MinValueValidator(0.2)]
- On the form, type in 0.2 and save -> ValidationError: Ensure this value is greater than or equal to 0.2.
Expected behavior: The form should not raise any ValidationErrors (according to the error message)
Change History (2)
comment:1 by , 26 hours ago
Cc: | added |
---|
comment:2 by , 25 hours ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
This appears to be a duplicate of #32037
The logic is correct. I guess this is what is causing confusion
And so...