Skip to content
Browse files

Fixed #8746: Check data in raw_id_fields more closely. Thanks, dgouldin

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 843a954 commit 5c321780c27b35a67c759f5062383786f98332fa @jacobian jacobian committed
Showing with 7 additions and 0 deletions.
  1. +3 −0 django/forms/
  2. +4 −0 tests/modeltests/model_forms/
3 django/forms/
@@ -760,6 +760,7 @@ class ModelMultipleChoiceField(ModelChoiceField):
'list': _(u'Enter a list of values.'),
'invalid_choice': _(u'Select a valid choice. %s is not one of the'
u' available choices.'),
+ 'invalid_pk_value': _(u'"%s" is not a valid value for a primary key.')
def __init__(self, queryset, cache_choices=False, required=True,
@@ -782,6 +783,8 @@ def clean(self, value):
obj = self.queryset.get(pk=val)
except self.queryset.model.DoesNotExist:
raise ValidationError(self.error_messages['invalid_choice'] % val)
+ except ValueError:
+ raise ValidationError(self.error_messages['invalid_pk_value'] % val)
return final_values
4 tests/modeltests/model_forms/
@@ -857,6 +857,10 @@ def __unicode__(self):
Traceback (most recent call last):
ValidationError: [u'Enter a list of values.']
+>>> f.clean(['fail'])
+Traceback (most recent call last):
+ValidationError: [u'"fail" is not a valid value for a primary key.']
# Add a Category object *after* the ModelMultipleChoiceField has already been
# instantiated. This proves clean() checks the database during clean() rather

0 comments on commit 5c32178

Please sign in to comment.
Something went wrong with that request. Please try again.