netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
16.09k stars 2.58k forks source link

Viewing devices "'MultipleObjectsReturned' object is not callable" #72

Closed bellwood closed 8 years ago

bellwood commented 8 years ago

This occurred after I assigned a /32 "Primary IP" to the fxp0 interfaces on both my edge routers (devices 2 and 3)

TypeError at /dcim/devices/2/
'MultipleObjectsReturned' object is not callable
Request Method: GET
Request URL:    http://x.x.x.x/dcim/devices/2/
Django Version: 1.9.7
Exception Type: TypeError
Exception Value:    
'MultipleObjectsReturned' object is not callable
Exception Location: /opt/netbox/netbox/dcim/models.py in get_connected_interface, line 785
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:    Tue, 28 Jun 2016 12:27:50 +0000
Error during template rendering

In template /opt/netbox/netbox/templates/dcim/device.html, error at line 0
'MultipleObjectsReturned' object is not callable
1   {% extends '_base.html' %}
2   {% load static from staticfiles %}
3   {% load render_table from django_tables2 %}
4   {% load helpers %}
5   
6   {% block title %}{{ device }}{% endblock %}
7   
8   {% block content %}
9   {% include 'dcim/inc/_device_header.html' with active_tab='info' %}
10  <div class="row">
Environment:

Request Method: GET
Request URL: http://x.x.x.x/dcim/devices/2/

Django Version: 1.9.7
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'debug_toolbar',
 'django_tables2',
 'rest_framework',
 'rest_framework_swagger',
 'circuits',
 'dcim',
 'ipam',
 'extras',
 'secrets',
 'users',
 'utilities')
Installed Middleware:
(u'debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'utilities.middleware.LoginRequiredMiddleware')

Template error:
In template /opt/netbox/netbox/templates/dcim/device.html, error at line 0
   'MultipleObjectsReturned' object is not callable   1 : {% extends '_base.html' %}
   2 : {% load static from staticfiles %}
   3 : {% load render_table from django_tables2 %}
   4 : {% load helpers %}
   5 : 
   6 : {% block title %}{{ device }}{% endblock %}
   7 : 
   8 : {% block content %}
   9 : {% include 'dcim/inc/_device_header.html' with active_tab='info' %}
   10 : <div class="row">

Traceback:

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/opt/netbox/netbox/dcim/views.py" in device
  542.         'related_devices': related_devices,

File "/usr/local/lib/python2.7/dist-packages/django/shortcuts.py" in render
  67.             template_name, context, request=request, using=using)

File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in render_to_string
  97.         return template.render(context, request)

File "/usr/local/lib/python2.7/dist-packages/django/template/backends/django.py" in render
  95.             return self.template.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  206.                     return self._render(context)

File "/usr/local/lib/python2.7/dist-packages/django/test/utils.py" in instrumented_test_render
  92.     return self.nodelist.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  992.                 bit = node.render_annotated(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render_annotated
  959.             return self.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py" in render
  173.         return compiled_parent._render(context)

File "/usr/local/lib/python2.7/dist-packages/django/test/utils.py" in instrumented_test_render
  92.     return self.nodelist.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  992.                 bit = node.render_annotated(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render_annotated
  959.             return self.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py" in render
  69.                 result = block.nodelist.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  992.                 bit = node.render_annotated(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render_annotated
  959.             return self.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py" in render
  326.                 return nodelist.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  992.                 bit = node.render_annotated(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render_annotated
  959.             return self.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py" in render
  220.                     nodelist.append(node.render_annotated(context))

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render_annotated
  959.             return self.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py" in render
  209.                 return template.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  208.                 return self._render(context)

File "/usr/local/lib/python2.7/dist-packages/django/test/utils.py" in instrumented_test_render
  92.     return self.nodelist.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  992.                 bit = node.render_annotated(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render_annotated
  959.             return self.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py" in render
  326.                 return nodelist.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  992.                 bit = node.render_annotated(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render_annotated
  959.             return self.render(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py" in render
  582.                   six.iteritems(self.extra_context)}

File "/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py" in <dictcomp>
  581.         values = {key: val.resolve(context) for key, val in

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in resolve
  709.                 obj = self.var.resolve(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in resolve
  850.             value = self._resolve_lookup(context)

File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in _resolve_lookup
  913.                             current = current()

File "/opt/netbox/netbox/dcim/models.py" in get_connected_interface
  785.             raise e("Multiple connections found for {0} interface {1}!".format(self.device, self))

Exception Type: TypeError at /dcim/devices/2/
Exception Value: 'MultipleObjectsReturned' object is not callable
jeremystretch commented 8 years ago

The error indicates that multiple InterfaceConnections have been found for an Interface, which of course should never happen. Assigning a primary IP to a device shouldn't have any effect regarding interface connections. Can you check whether device 2 has any duplicate connections?

bellwood commented 8 years ago

It looks like the iBGP link between both edge routers is listed twice

edge1 -> edge2 edge2 -> edge1

I dont see an edit/delete connections option though to fix this :/

bellwood commented 8 years ago

Perhaps a bug in the interface validation checks - presumably I should not have been allowed to import:

{2},xe-2/2/0,{3},xe-2/2/0,connected {3},xe-2/2/0,{2},xe-2/2/0,connected

bellwood commented 8 years ago

Just notating the shell-based solution we talked about in the IRC channel should anyone stumble across this:

/opt/netbox/netbox# ./manage.py shell

>>> from dcim.models import InterfaceConnection

>>> InterfaceConnection.objects.filter(interface_a__device__name='edge1', interface_a__name='xe-2/2/0').delete()

(1, {u'dcim.InterfaceConnection': 1})

>>> quit()
jeremystretch commented 8 years ago

presumably I should not have been allowed to import

This is the root of the problem. NetBox should not have created those mirrored interface connections.