mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #27904 -- Added a system check that Field.validators are callable.
This commit is contained in:
parent
75503a823f
commit
a452dddb25
4 changed files with 39 additions and 1 deletions
|
@ -205,6 +205,23 @@ class CharFieldTests(TestCase):
|
|||
]
|
||||
self.assertEqual(errors, expected)
|
||||
|
||||
def test_bad_validators(self):
|
||||
class Model(models.Model):
|
||||
field = models.CharField(max_length=10, validators=[True])
|
||||
|
||||
field = Model._meta.get_field('field')
|
||||
self.assertEqual(field.check(), [
|
||||
Error(
|
||||
"All 'validators' must be callable.",
|
||||
hint=(
|
||||
"validators[0] (True) isn't a function or instance of a "
|
||||
"validator class."
|
||||
),
|
||||
obj=field,
|
||||
id='fields.E008',
|
||||
),
|
||||
])
|
||||
|
||||
@unittest.skipUnless(connection.vendor == 'mysql',
|
||||
"Test valid only for MySQL")
|
||||
def test_too_long_char_field_under_mysql(self):
|
||||
|
|
|
@ -102,7 +102,7 @@ class RelativeFieldTests(SimpleTestCase):
|
|||
m2m = models.ManyToManyField(
|
||||
Model,
|
||||
null=True,
|
||||
validators=[''],
|
||||
validators=[lambda x: x],
|
||||
limit_choices_to={'name': 'test_name'},
|
||||
through='ThroughModel',
|
||||
through_fields=('modelm2m', 'model'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue