Ticket #8974: 8974.patch

File 8974.patch, 912 bytes (added by Samuel Cormier-Iijima, 11 years ago)

Simple fix for catching ValueError

  • django/forms/models.py

     
    648648        try:
    649649            key = self.to_field_name or 'pk'
    650650            value = self.queryset.get(**{key: value})
    651         except self.queryset.model.DoesNotExist:
     651        except (self.queryset.model.DoesNotExist, ValueError):
    652652            raise ValidationError(self.error_messages['invalid_choice'])
    653653        return value
    654654
     
    680680        for val in value:
    681681            try:
    682682                obj = self.queryset.get(pk=val)
    683             except self.queryset.model.DoesNotExist:
     683            except (self.queryset.model.DoesNotExist, ValueError):
    684684                raise ValidationError(self.error_messages['invalid_choice'] % val)
    685685            else:
    686686                final_values.append(obj)
Back to Top