From 67282882faae39e21fac626284a5ed3be841911e Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 12 May 2017 15:55:18 -0400 Subject: [PATCH] Fixed RelatedObjectDoesNotExist error when trying to create a new device --- netbox/dcim/forms.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index 09ea6af8c..cdfc8d0a8 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -596,7 +596,8 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldForm): # Initialize helper selectors instance = kwargs.get('instance') - if instance and instance.device_type is not None: + # Using hasattr() instead of "is not None" to avoid RelatedObjectDoesNotExist on required field + if instance and hasattr(instance, 'device_type'): initial = kwargs.get('initial', {}) initial['manufacturer'] = instance.device_type.manufacturer kwargs['initial'] = initial