Added code to catch a form error regularly caused by form spam and return a failure instead of triggering a server 500.

- Legacy-Id: 16728
This commit is contained in:
Henrik Levkowetz 2019-09-10 16:10:11 +00:00
parent 81bc17533a
commit 3160f55597

View file

@ -89,7 +89,10 @@ class SearchableDocumentsField(forms.CharField):
value = super(SearchableDocumentsField, self).clean(value)
pks = self.parse_select2_value(value)
objs = self.model.objects.filter(pk__in=pks)
try:
objs = self.model.objects.filter(pk__in=pks)
except ValueError as e:
raise forms.ValidationError("Unexpected field value; %s" % e)
found_pks = [ str(o.pk) for o in objs ]
failed_pks = [ x for x in pks if x not in found_pks ]