mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #28431 -- Added a system check for BinaryField to prevent strings defaults.
Thanks Claude Paroz for the initial patch.
This commit is contained in:
committed by
Mariusz Felisiak
parent
dc53f2135b
commit
981dd6dd71
@@ -2252,6 +2252,21 @@ class BinaryField(Field):
|
||||
if self.max_length is not None:
|
||||
self.validators.append(validators.MaxLengthValidator(self.max_length))
|
||||
|
||||
def check(self, **kwargs):
|
||||
return [*super().check(**kwargs), *self._check_str_default_value()]
|
||||
|
||||
def _check_str_default_value(self):
|
||||
if self.has_default() and isinstance(self.default, str):
|
||||
return [
|
||||
checks.Error(
|
||||
"BinaryField's default cannot be a string. Use bytes "
|
||||
"content instead.",
|
||||
obj=self,
|
||||
id='fields.E170',
|
||||
)
|
||||
]
|
||||
return []
|
||||
|
||||
def deconstruct(self):
|
||||
name, path, args, kwargs = super().deconstruct()
|
||||
if self.editable:
|
||||
|
||||
Reference in New Issue
Block a user