API endpoint for interface-connections includes circuit terminations #2417

Closed
opened 2025-12-29 17:25:54 +01:00 by adam · 2 comments
Owner

Originally created by @candlerb on GitHub (Feb 28, 2019).

Environment

  • Python version: 3.5.2
  • NetBox version: 2.5.7

Steps to Reproduce

  1. curl http://netbox:8000/api/dcim/interface-connections/?limit=0
  2. curl http://netbox:8000/api/dcim/interface-connections/?limit=1000

The limit has to be zero or large to reproduce the error - maybe relates to paging?

Originally reported at https://groups.google.com/forum/#!topic/netbox-discuss/zKK_PRlmI3M

Expected Behavior

Regular JSON response, as you get with limit=1 or limit=2.

Observed Behavior

Backtrace:

Internal Server Error: /api/dcim/interface-connections/
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/fields.py", line 454, in get_attribute
    return get_attribute(instance, self.source_attrs)
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/fields.py", line 102, in get_attribute
    instance = getattr(instance, attr)
AttributeError: 'CircuitTermination' object has no attribute 'name'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/viewsets.py", line 116, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/views.py", line 495, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/views.py", line 455, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/views.py", line 492, in dispatch
    response = handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/mixins.py", line 45, in list
    return self.get_paginated_response(serializer.data)
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 765, in data
    ret = super(ListSerializer, self).data
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 262, in data
    self._data = self.to_representation(self.instance)
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 683, in to_representation
    self.child.to_representation(item) for item in iterable
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 683, in <listcomp>
    self.child.to_representation(item) for item in iterable
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 527, in to_representation
    ret[field.field_name] = field.to_representation(attribute)
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 514, in to_representation
    attribute = field.get_attribute(instance)
  File "/usr/local/lib/python3.5/dist-packages/rest_framework/fields.py", line 475, in get_attribute
    raise type(exc)(msg)
AttributeError: Got AttributeError when attempting to get a value for field `name` on serializer `NestedInterfaceSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `CircuitTermination` instance.
Original exception text was: 'CircuitTermination' object has no attribute 'name'.
[28/Feb/2019 08:05:42] "GET /api/dcim/interface-connections/?limit=0 HTTP/1.1" 500 21497
Originally created by @candlerb on GitHub (Feb 28, 2019). ### Environment * Python version: 3.5.2 * NetBox version: 2.5.7 ### Steps to Reproduce 1. `curl http://netbox:8000/api/dcim/interface-connections/?limit=0` 2. `curl http://netbox:8000/api/dcim/interface-connections/?limit=1000` The limit has to be zero or large to reproduce the error - maybe relates to paging? Originally reported at https://groups.google.com/forum/#!topic/netbox-discuss/zKK_PRlmI3M ### Expected Behavior Regular JSON response, as you get with limit=1 or limit=2. ### Observed Behavior Backtrace: ``` Internal Server Error: /api/dcim/interface-connections/ Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/rest_framework/fields.py", line 454, in get_attribute return get_attribute(instance, self.source_attrs) File "/usr/local/lib/python3.5/dist-packages/rest_framework/fields.py", line 102, in get_attribute instance = getattr(instance, attr) AttributeError: 'CircuitTermination' object has no attribute 'name' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 126, in _get_response response = self.process_exception_by_middleware(e, request) File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 124, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.5/dist-packages/django/views/decorators/csrf.py", line 54, in wrapped_view return view_func(*args, **kwargs) File "/usr/local/lib/python3.5/dist-packages/rest_framework/viewsets.py", line 116, in view return self.dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.5/dist-packages/rest_framework/views.py", line 495, in dispatch response = self.handle_exception(exc) File "/usr/local/lib/python3.5/dist-packages/rest_framework/views.py", line 455, in handle_exception self.raise_uncaught_exception(exc) File "/usr/local/lib/python3.5/dist-packages/rest_framework/views.py", line 492, in dispatch response = handler(request, *args, **kwargs) File "/usr/local/lib/python3.5/dist-packages/rest_framework/mixins.py", line 45, in list return self.get_paginated_response(serializer.data) File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 765, in data ret = super(ListSerializer, self).data File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 262, in data self._data = self.to_representation(self.instance) File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 683, in to_representation self.child.to_representation(item) for item in iterable File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 683, in <listcomp> self.child.to_representation(item) for item in iterable File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 527, in to_representation ret[field.field_name] = field.to_representation(attribute) File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 514, in to_representation attribute = field.get_attribute(instance) File "/usr/local/lib/python3.5/dist-packages/rest_framework/fields.py", line 475, in get_attribute raise type(exc)(msg) AttributeError: Got AttributeError when attempting to get a value for field `name` on serializer `NestedInterfaceSerializer`. The serializer field might be named incorrectly and not match any attribute or key on the `CircuitTermination` instance. Original exception text was: 'CircuitTermination' object has no attribute 'name'. [28/Feb/2019 08:05:42] "GET /api/dcim/interface-connections/?limit=0 HTTP/1.1" 500 21497 ```
adam added the type: bugstatus: accepted labels 2025-12-29 17:25:54 +01:00
adam closed this issue 2025-12-29 17:25:54 +01:00
Author
Owner

@jeremystretch commented on GitHub (Feb 28, 2019):

The problem is the API endpoint (unlike the web UI view) is returning not only interface-to-interface connections, but also interface-to-circuit terminations. The exception is raised as soon as the first interface-to-circuit connection is encountered.

Going to fix this by filtering out interface-to-circuit connections to match the UI functionality.

@jeremystretch commented on GitHub (Feb 28, 2019): The problem is the API endpoint (unlike the web UI view) is returning not only interface-to-interface connections, but also interface-to-circuit terminations. The exception is raised as soon as the first interface-to-circuit connection is encountered. Going to fix this by filtering out interface-to-circuit connections to match the UI functionality.
Author
Owner

@jeremystretch commented on GitHub (Feb 28, 2019):

Fixed in 3e6033e

@jeremystretch commented on GitHub (Feb 28, 2019): Fixed in 3e6033e
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2417