Improve API error handling when a list is given as a choice value

See https://groups.google.com/forum/#!topic/netbox-discuss/H7xIrwVnOSM
This commit is contained in:
Brian Candler 2019-08-10 10:04:13 +01:00
parent f18c3be745
commit e8d4561db1

View File

@ -1,4 +1,5 @@
from collections import OrderedDict
from collections.abc import Hashable
import pytz
from django.conf import settings
@ -101,7 +102,7 @@ class ChoiceField(Field):
except ValueError:
pass
if data not in self._choices:
if not isinstance(data, Hashable) or data not in self._choices:
raise ValidationError("{} is not a valid choice.".format(data))
return data