1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #29860 -- Allowed BaseValidator to accept a callable limit_value.

This commit is contained in:
buzzi
2018-10-17 14:52:19 +00:00
committed by Tim Graham
parent 5e3463f6bc
commit 24cae0bedc
4 changed files with 34 additions and 7 deletions

View File

@@ -317,8 +317,9 @@ class BaseValidator:
def __call__(self, value):
cleaned = self.clean(value)
params = {'limit_value': self.limit_value, 'show_value': cleaned, 'value': value}
if self.compare(cleaned, self.limit_value):
limit_value = self.limit_value() if callable(self.limit_value) else self.limit_value
params = {'limit_value': limit_value, 'show_value': cleaned, 'value': value}
if self.compare(cleaned, limit_value):
raise ValidationError(self.message, code=self.code, params=params)
def __eq__(self, other):