From 66d1e88f5a7ed9e9a3b2e03288c9e1b12d2baf16 Mon Sep 17 00:00:00 2001 From: Anthony Ruhier Date: Wed, 6 Mar 2019 15:47:39 +0100 Subject: [PATCH] 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 --- netbox/utilities/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox/utilities/api.py b/netbox/utilities/api.py index 530372fb9..01eb2e5cf 100644 --- a/netbox/utilities/api.py +++ b/netbox/utilities/api.py @@ -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")