Repository: netbox-community/netbox

Issue:
Can't connect interfaces
Issue type: bug report

**Python version:**
2.7.6
**NetBox version:**
1.9.0

1. Open device
2. Click green "connect" + button next to interface
3. Type name of device in search and select from list
4. Select interface from dropdown
5. Click "Connect" button

I'm returned to the same page. 

If I click "connect" again (fields above still populated with same data), I get this:
ValueError at /dcim/devices/6/interface-connections/add/
invalid literal for int() with base 10: ''
Request Method:	POST
Request URL:	http://netbox/dcim/devices/6/interface-connections/add/
Django Version:	1.10.6
Exception Type:	ValueError
Exception Value:	
invalid literal for int() with base 10: ''
Exception Location:	/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py in get_prep_value, line 946
Python Executable:	/usr/bin/python
Python Version:	2.7.6
Python Path:	
['/opt/netbox/netbox/netbox',
 '/opt/netbox/netbox',
 '/usr/bin',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages']
Server time:	Thu, 2 Mar 2017 14:56:57 -0800

If I click "cancel" instead at that step, I'm returned to the same device but don't see the connection I attempted made. 


Discussion:

Resolving patch:
diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py
--- a/netbox/dcim/forms.py
+++ b/netbox/dcim/forms.py
@@ -82,7 +82,7 @@ class Meta:
 #
 
 class SiteForm(BootstrapMixin, CustomFieldForm):
-    region = TreeNodeChoiceField(queryset=Region.objects.all())
+    region = TreeNodeChoiceField(queryset=Region.objects.all(), required=False)
     slug = SlugField()
     comments = CommentField()
 
@@ -1468,19 +1468,13 @@ def __init__(self, device_a, *args, **kwargs):
         ]
 
         # Initialize rack_b choices if site_b is set
-        if self.is_bound and self.data.get('site_b'):
-            self.fields['rack_b'].queryset = Rack.objects.filter(site__pk=self.data['site_b'])
-        elif self.initial.get('site_b'):
+        if self.initial.get('site_b'):
             self.fields['rack_b'].queryset = Rack.objects.filter(site=self.initial['site_b'])
         else:
             self.fields['rack_b'].choices = []
 
         # Initialize device_b choices if rack_b or site_b is set
-        if self.is_bound and self.data.get('rack_b'):
-            self.fields['device_b'].queryset = Device.objects.filter(rack__pk=self.data['rack_b'])
-        elif self.is_bound and self.data.get('site_b'):
-            self.fields['device_b'].queryset = Device.objects.filter(site__pk=self.data['site_b'], rack__isnull=True)
-        elif self.initial.get('rack_b'):
+        if self.initial.get('rack_b'):
             self.fields['device_b'].queryset = Device.objects.filter(rack=self.initial['rack_b'])
         elif self.initial.get('site_b'):
             self.fields['device_b'].queryset = Device.objects.filter(site=self.initial['site_b'], rack__isnull=True)
@@ -1488,13 +1482,7 @@ def __init__(self, device_a, *args, **kwargs):
             self.fields['device_b'].choices = []
 
         # Initialize interface_b choices if device_b is set
-        if self.is_bound:
-            device_b_interfaces = Interface.objects.filter(device=self.data['device_b']).exclude(
-                form_factor__in=VIRTUAL_IFACE_TYPES
-            ).select_related(
-                'circuit_termination', 'connected_as_a', 'connected_as_b'
-            )
-        elif self.initial.get('device_b'):
+        if self.initial.get('device_b'):
             device_b_interfaces = Interface.objects.filter(device=self.initial['device_b']).exclude(
                 form_factor__in=VIRTUAL_IFACE_TYPES
             ).select_related(
diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py
--- a/netbox/netbox/settings.py
+++ b/netbox/netbox/settings.py
@@ -12,7 +12,7 @@
                                "the documentation.")
 
 
-VERSION = '1.9.0'
+VERSION = '1.9.0-r1'
 
 # Import local configuration
 for setting in ['ALLOWED_HOSTS', 'DATABASE', 'SECRET_KEY']:


Test patch: