diff options
| author | Claude Paroz <claude@2xlibre.net> | 2013-03-06 08:28:12 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-03-06 08:30:23 +0100 |
| commit | 22be90dd171deebd0cf52bdd749f27b18e29a2f2 (patch) | |
| tree | 9606a12232fa9c9d978cf3161eec758cffbbcf37 | |
| parent | d9330d5be2ee60b208dcab2616eb164ea2e6bf36 (diff) | |
Fixed #19989 -- Suppressed UnicodeWarning during BinaryField validation
Thanks Aymeric Augustin for the report and Simon Charette for the
review.
| -rw-r--r-- | django/db/models/fields/__init__.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index f8ec205611..f9f913bc1b 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -57,6 +57,7 @@ class Field(object): # Designates whether empty strings fundamentally are allowed at the # database level. empty_strings_allowed = True + empty_values = list(validators.EMPTY_VALUES) # These track each time a Field instance is created. Used to retain order. # The auto_creation_counter is used for fields that Django implicitly @@ -157,7 +158,7 @@ class Field(object): return value def run_validators(self, value): - if value in validators.EMPTY_VALUES: + if value in self.empty_values: return errors = [] @@ -184,7 +185,7 @@ class Field(object): # Skip validation for non-editable fields. return - if self._choices and value not in validators.EMPTY_VALUES: + if self._choices and value not in self.empty_values: for option_key, option_value in self.choices: if isinstance(option_value, (list, tuple)): # This is an optgroup, so look inside the group for @@ -200,7 +201,7 @@ class Field(object): if value is None and not self.null: raise exceptions.ValidationError(self.error_messages['null']) - if not self.blank and value in validators.EMPTY_VALUES: + if not self.blank and value in self.empty_values: raise exceptions.ValidationError(self.error_messages['blank']) def clean(self, value, model_instance): @@ -1295,6 +1296,7 @@ class URLField(CharField): class BinaryField(Field): description = _("Raw binary data") + empty_values = [None, b''] def __init__(self, *args, **kwargs): kwargs['editable'] = False |
