1
0
mirror of https://github.com/django/django.git synced 2025-10-30 00:56:09 +00:00

Fixed #22808 -- Made ModelMultipleChoiceField validation more robust to invalid data types..

Thanks Mattias Lindvall for the report and inital patch.
This commit is contained in:
Niclas Olofsson
2014-07-26 11:06:30 +02:00
committed by Tim Graham
parent 7579080899
commit cdc25ac474
3 changed files with 16 additions and 2 deletions

View File

@@ -1179,7 +1179,7 @@ class ModelChoiceField(ChoiceField):
try:
key = self.to_field_name or 'pk'
value = self.queryset.get(**{key: value})
except (ValueError, self.queryset.model.DoesNotExist):
except (ValueError, TypeError, self.queryset.model.DoesNotExist):
raise ValidationError(self.error_messages['invalid_choice'], code='invalid_choice')
return value
@@ -1227,7 +1227,7 @@ class ModelMultipleChoiceField(ModelChoiceField):
for pk in value:
try:
self.queryset.filter(**{key: pk})
except ValueError:
except (ValueError, TypeError):
raise ValidationError(
self.error_messages['invalid_pk_value'],
code='invalid_pk_value',