Cable Trace leads to "division by zero" if the last cable is not connected #10408

Closed
opened 2025-12-29 21:31:06 +01:00 by adam · 5 comments
Owner

Originally created by @knebb on GitHub (Oct 27, 2024).

Originally assigned to: @bctiemann on GitHub.

Deployment Type

Self-hosted

Triage priority

N/A

NetBox Version

NetBox Community v4.1.3

Python Version

3.11

Steps to Reproduce

Have a switch (or similar) with an interface connected through multiple passive components (ie patchpanel, wall-plugs) to a device with an interface.
From switch, do cable trace on this interface - it will display all in-between interfaces (as expected).
Delete the device without deleting or disconnecting its cable will result in an unterminated cable (might be by design).
Trace the cable again from the switch interface.

Expected Behavior

I expect the cable trace to walk through until the last (unterminated) cable and show either the last device or the unterminated cable to trace down the still existing cables.

Observed Behavior

Results in an error without displaying any svg cable date:

<class 'ZeroDivisionError'>

division by zero

Python-Version: 3.11.2
NetBox-Version: 4.1.3
Plugins: 
  netbox_topology_views: 4.0.1
Originally created by @knebb on GitHub (Oct 27, 2024). Originally assigned to: @bctiemann on GitHub. ### Deployment Type Self-hosted ### Triage priority N/A ### NetBox Version NetBox Community v4.1.3 ### Python Version 3.11 ### Steps to Reproduce Have a switch (or similar) with an interface connected through multiple passive components (ie patchpanel, wall-plugs) to a device with an interface. From switch, do cable trace on this interface - it will display all in-between interfaces (as expected). Delete the device without deleting or disconnecting its cable will result in an unterminated cable (might be by [design](https://github.com/netbox-community/netbox/issues/10769)). Trace the cable again from the switch interface. ### Expected Behavior I expect the cable trace to walk through until the last (unterminated) cable and show either the last device or the unterminated cable to trace down the still existing cables. ### Observed Behavior Results in an error without displaying any svg cable date: ``` <class 'ZeroDivisionError'> division by zero Python-Version: 3.11.2 NetBox-Version: 4.1.3 Plugins: netbox_topology_views: 4.0.1 ```
adam added the type: bugstatus: acceptednetboxtopic: cablingseverity: low labels 2025-12-29 21:31:06 +01:00
adam closed this issue 2025-12-29 21:31:06 +01:00
Author
Owner

@arthanson commented on GitHub (Oct 29, 2024):

@knebb Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.

Can you please provide complete reproduction steps, something like:

  1. create device A with name=xxx,
  2. Add interface 1 to device A
  3. ...
  4. Connect cable to interface 1 to ...
  5. Click the cable trace button and see the error.
@arthanson commented on GitHub (Oct 29, 2024): @knebb Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports. Can you please provide complete reproduction steps, something like: 1. create device A with name=xxx, 2. Add interface 1 to device A 3. ... 4. Connect cable to interface 1 to ... 12. Click the cable trace button and see the error.
Author
Owner

@knebb commented on GitHub (Oct 29, 2024):

Hi,

I though it is indeed self explanatory. However; I will try again:

Create a "switch" A with at least a single interface (switches usually have multiple...).
Create at least one device B with a frontport and a rearport.
Create another device C with at least one interface (like a PC or something).

Connect one interface from the switch A to rearport of B.
Connect frontport of B with interface of C.

Go to the "Interfaces" page of switch A. Select the "Trace" button of the interface you connected with the above steps.
You will get the cable trace in SVG format and at the bottom you will see device C.

Go to devices and delete device C. Do NOT delete or edit the cables from above steps!
You will end up with an orphaned cable (which will not do any harm).

Go again to the "Interfaces" page of the switch A. Klick on the "Trace" button again. Instead of showing the connected trace through B to the orphaned cable you will get no SVG graphic.

Click on the Download SVG button and you will get an "Server error" with the "Division by zero" error I mentioned.

I (And others) do not mind about the orphan cable. But it should show the SVG graph to the last connected device. Otherwise I am not able to track or trace where the connected interface of the switch ends.

Hope it's clear now.

@knebb commented on GitHub (Oct 29, 2024): Hi, I though it is indeed self explanatory. However; I will try again: Create a "switch" A with at least a single interface (switches usually have multiple...). Create at least one device B with a frontport and a rearport. Create another device C with at least one interface (like a PC or something). Connect one interface from the switch A to rearport of B. Connect frontport of B with interface of C. Go to the "Interfaces" page of switch A. Select the "Trace" button of the interface you connected with the above steps. You will get the cable trace in SVG format and at the bottom you will see device C. Go to devices and delete device C. Do NOT delete or edit the cables from above steps! You will end up with an orphaned cable (which will not do any harm). Go again to the "Interfaces" page of the switch A. Klick on the "Trace" button again. Instead of showing the connected trace through B to the orphaned cable you will get no SVG graphic. Click on the Download SVG button and you will get an "Server error" with the "Division by zero" error I mentioned. I (And others) do not mind about the orphan cable. But it should show the SVG graph to the last connected device. Otherwise I am not able to track or trace where the connected interface of the switch ends. Hope it's clear now.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 9, 2024):

This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.

@github-actions[bot] commented on GitHub (Nov 9, 2024): This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.
Author
Owner

@knebb commented on GitHub (Nov 9, 2024):

@arthanson
I added the required information (see above). What else can I do?

@knebb commented on GitHub (Nov 9, 2024): @arthanson I added the required information (see above). What else can I do?
Author
Owner

@jeremystretch commented on GitHub (Dec 6, 2024):

I was able to reproduce this on NetBox v4.1.7. Stack trace below.

Internal Server Error: /api/dcim/interfaces/1620/trace/
Traceback (most recent call last):
  File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
    return view_func(request, *args, **kwargs)
  File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/rest_framework/viewsets.py", line 124, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/jstretch/projects/netbox/netbox/netbox/api/viewsets/__init__.py", line 135, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/jstretch/projects/netbox/netbox/dcim/api/views.py", line 55, in trace
    return HttpResponse(drawing.render().tostring(), content_type='image/svg+xml')
  File "/home/jstretch/projects/netbox/netbox/dcim/svg/cables.py", line 368, in render
    parent_object_nodes, far_terminations = self.draw_far_objects(obj_list, far_ends)
  File "/home/jstretch/projects/netbox/netbox/dcim/svg/cables.py", line 273, in draw_far_objects
    width = self.width / len(objects)
ZeroDivisionError: division by zero
@jeremystretch commented on GitHub (Dec 6, 2024): I was able to reproduce this on NetBox v4.1.7. Stack trace below. ``` Internal Server Error: /api/dcim/interfaces/1620/trace/ Traceback (most recent call last): File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper return view_func(request, *args, **kwargs) File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/rest_framework/viewsets.py", line 124, in view return self.dispatch(request, *args, **kwargs) File "/home/jstretch/projects/netbox/netbox/netbox/api/viewsets/__init__.py", line 135, in dispatch return super().dispatch(request, *args, **kwargs) File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch response = self.handle_exception(exc) File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception self.raise_uncaught_exception(exc) File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception raise exc File "/home/jstretch/projects/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch response = handler(request, *args, **kwargs) File "/home/jstretch/projects/netbox/netbox/dcim/api/views.py", line 55, in trace return HttpResponse(drawing.render().tostring(), content_type='image/svg+xml') File "/home/jstretch/projects/netbox/netbox/dcim/svg/cables.py", line 368, in render parent_object_nodes, far_terminations = self.draw_far_objects(obj_list, far_ends) File "/home/jstretch/projects/netbox/netbox/dcim/svg/cables.py", line 273, in draw_far_objects width = self.width / len(objects) ZeroDivisionError: division by zero ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10408