diff options
| author | Adam Chainz <me@adamj.eu> | 2017-03-05 16:50:33 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-03-11 12:27:29 -0500 |
| commit | a452dddb253ff4fdd793351dac73eeef4d86b83e (patch) | |
| tree | 7f2aacb79f04d8404210c7ce7f68ef0bc0f4e3de /django | |
| parent | 75503a823f6358892fff5aeb3691683ad9cc5a60 (diff) | |
Fixed #27904 -- Added a system check that Field.validators are callable.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/fields/__init__.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 79a983b8fa..d9e2bac348 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -204,6 +204,7 @@ class Field(RegisterLookupMixin): errors.extend(self._check_db_index()) errors.extend(self._check_null_allowed_for_primary_keys()) errors.extend(self._check_backend_specific_checks(**kwargs)) + errors.extend(self._check_validators()) errors.extend(self._check_deprecation_details()) return errors @@ -302,6 +303,25 @@ class Field(RegisterLookupMixin): return connections[db].validation.check_field(self, **kwargs) return [] + def _check_validators(self): + errors = [] + for i, validator in enumerate(self.validators): + if not callable(validator): + errors.append( + checks.Error( + "All 'validators' must be callable.", + hint=( + "validators[{i}] ({repr}) isn't a function or " + "instance of a validator class.".format( + i=i, repr=repr(validator), + ) + ), + obj=self, + id='fields.E008', + ) + ) + return errors + def _check_deprecation_details(self): if self.system_check_removed_details is not None: return [ |
