mirror of
https://github.com/django/django.git
synced 2025-08-31 15:57:45 +00:00
Fixed #30328 -- Fixed crash of IntegerField.validators when limit_value in a custom validator is callable.
This commit is contained in:
parent
aed89adad5
commit
a14c0fda15
4 changed files with 47 additions and 26 deletions
|
@ -98,27 +98,31 @@ class IntegerFieldTests(TestCase):
|
|||
"""
|
||||
min_backend_value, max_backend_value = self.backend_range
|
||||
|
||||
if min_backend_value is not None:
|
||||
min_custom_value = min_backend_value + 1
|
||||
ranged_value_field = self.model._meta.get_field('value').__class__(
|
||||
validators=[validators.MinValueValidator(min_custom_value)]
|
||||
)
|
||||
field_range_message = validators.MinValueValidator.message % {
|
||||
'limit_value': min_custom_value,
|
||||
}
|
||||
with self.assertRaisesMessage(ValidationError, "[%r]" % field_range_message):
|
||||
ranged_value_field.run_validators(min_backend_value - 1)
|
||||
for callable_limit in (True, False):
|
||||
with self.subTest(callable_limit=callable_limit):
|
||||
if min_backend_value is not None:
|
||||
min_custom_value = min_backend_value + 1
|
||||
limit_value = (lambda: min_custom_value) if callable_limit else min_custom_value
|
||||
ranged_value_field = self.model._meta.get_field('value').__class__(
|
||||
validators=[validators.MinValueValidator(limit_value)]
|
||||
)
|
||||
field_range_message = validators.MinValueValidator.message % {
|
||||
'limit_value': min_custom_value,
|
||||
}
|
||||
with self.assertRaisesMessage(ValidationError, '[%r]' % field_range_message):
|
||||
ranged_value_field.run_validators(min_backend_value - 1)
|
||||
|
||||
if max_backend_value is not None:
|
||||
max_custom_value = max_backend_value - 1
|
||||
ranged_value_field = self.model._meta.get_field('value').__class__(
|
||||
validators=[validators.MaxValueValidator(max_custom_value)]
|
||||
)
|
||||
field_range_message = validators.MaxValueValidator.message % {
|
||||
'limit_value': max_custom_value,
|
||||
}
|
||||
with self.assertRaisesMessage(ValidationError, "[%r]" % field_range_message):
|
||||
ranged_value_field.run_validators(max_backend_value + 1)
|
||||
if max_backend_value is not None:
|
||||
max_custom_value = max_backend_value - 1
|
||||
limit_value = (lambda: max_custom_value) if callable_limit else max_custom_value
|
||||
ranged_value_field = self.model._meta.get_field('value').__class__(
|
||||
validators=[validators.MaxValueValidator(limit_value)]
|
||||
)
|
||||
field_range_message = validators.MaxValueValidator.message % {
|
||||
'limit_value': max_custom_value,
|
||||
}
|
||||
with self.assertRaisesMessage(ValidationError, '[%r]' % field_range_message):
|
||||
ranged_value_field.run_validators(max_backend_value + 1)
|
||||
|
||||
def test_types(self):
|
||||
instance = self.model(value=0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue