mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-13 19:18:16 -06:00
Error when ContentType is in wrong format
When spliting the ContentType returns only one item, assignating the app_label and model fails. The API returns a 500 error. Ensure that a ValidationError is returned if a ValueError is raised during the assignation
This commit is contained in:
parent
0c142f2078
commit
66d1e88f5a
@ -109,10 +109,10 @@ class ContentTypeField(Field):
|
||||
return "{}.{}".format(obj.app_label, obj.model)
|
||||
|
||||
def to_internal_value(self, data):
|
||||
app_label, model = data.split('.')
|
||||
try:
|
||||
app_label, model = data.split('.')
|
||||
return ContentType.objects.get_by_natural_key(app_label=app_label, model=model)
|
||||
except ContentType.DoesNotExist:
|
||||
except (ContentType.DoesNotExist, ValueError):
|
||||
raise ValidationError("Invalid content type")
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user