Create cable error #7586

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

Originally created by @peterhill2 on GitHub (Feb 1, 2023).

NetBox version

v3.4.2

Python version

3.8

Steps to Reproduce

  1. Create cable with REST API with cable terminations to a circuit and an interface
  2. Issue experienced with API

Expected Behavior

A cable should be created with the 2 sides connected to the termination points.

Observed Behavior

netbox_1 | Internal Server Error: /api/dcim/cables/
netbox_1 | Traceback (most recent call last):
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
netbox_1 | response = get_response(request)
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
netbox_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
netbox_1 | return view_func(*args, **kwargs)
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/viewsets.py", line 125, in view
netbox_1 | return self.dispatch(request, *args, **kwargs)
netbox_1 | File "/opt/netbox/netbox/netbox/api/viewsets/init.py", line 118, in dispatch
netbox_1 | return super().dispatch(request, *args, **kwargs)
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
netbox_1 | response = self.handle_exception(exc)
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
netbox_1 | self.raise_uncaught_exception(exc)
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
netbox_1 | raise exc
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
netbox_1 | response = handler(request, *args, **kwargs)
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/mixins.py", line 18, in create
netbox_1 | serializer.is_valid(raise_exception=True)
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py", line 227, in is_valid
netbox_1 | self._validated_data = self.run_validation(self.initial_data)
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py", line 429, in run_validation
netbox_1 | value = self.validate(value)
netbox_1 | File "/opt/netbox/netbox/netbox/api/serializers/base.py", line 41, in validate
netbox_1 | instance.full_clean()
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1452, in full_clean
netbox_1 | self.clean()
netbox_1 | File "/opt/netbox/netbox/dcim/models/cables.py", line 148, in clean
netbox_1 | if self.pk is None and (not self.a_terminations or not self.b_terminations):
netbox_1 | File "/opt/netbox/netbox/dcim/models/cables.py", line 117, in a_terminations
netbox_1 | ct.termination for ct in self.terminations.all() if ct.cable_end == CableEndChoices.SIDE_A
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 164, in all
netbox_1 | return self.get_queryset()
netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/fields/related_descriptors.py", line 689, in get_queryset
netbox_1 | raise ValueError(
netbox_1 | ValueError: 'Cable' instance needs to have a primary key value before this relationship can be used.
netbox_1 | 172.19.0.1 - - [01/Feb/2023:07:13:28 +0000] "POST /api/dcim/cables/ HTTP/1.0" 500 1644 "-" "python-requests/2.24.0"

Originally created by @peterhill2 on GitHub (Feb 1, 2023). ### NetBox version v3.4.2 ### Python version 3.8 ### Steps to Reproduce 1. Create cable with REST API with cable terminations to a circuit and an interface 2. Issue experienced with API ### Expected Behavior A cable should be created with the 2 sides connected to the termination points. ### Observed Behavior netbox_1 | Internal Server Error: /api/dcim/cables/ netbox_1 | Traceback (most recent call last): netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner netbox_1 | response = get_response(request) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response netbox_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view netbox_1 | return view_func(*args, **kwargs) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/viewsets.py", line 125, in view netbox_1 | return self.dispatch(request, *args, **kwargs) netbox_1 | File "/opt/netbox/netbox/netbox/api/viewsets/__init__.py", line 118, in dispatch netbox_1 | return super().dispatch(request, *args, **kwargs) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch netbox_1 | response = self.handle_exception(exc) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception netbox_1 | self.raise_uncaught_exception(exc) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception netbox_1 | raise exc netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch netbox_1 | response = handler(request, *args, **kwargs) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/mixins.py", line 18, in create netbox_1 | serializer.is_valid(raise_exception=True) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py", line 227, in is_valid netbox_1 | self._validated_data = self.run_validation(self.initial_data) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py", line 429, in run_validation netbox_1 | value = self.validate(value) netbox_1 | File "/opt/netbox/netbox/netbox/api/serializers/base.py", line 41, in validate netbox_1 | instance.full_clean() netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1452, in full_clean netbox_1 | self.clean() netbox_1 | File "/opt/netbox/netbox/dcim/models/cables.py", line 148, in clean netbox_1 | if self.pk is None and (not self.a_terminations or not self.b_terminations): netbox_1 | File "/opt/netbox/netbox/dcim/models/cables.py", line 117, in a_terminations netbox_1 | ct.termination for ct in self.terminations.all() if ct.cable_end == CableEndChoices.SIDE_A netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 164, in all netbox_1 | return self.get_queryset() netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/fields/related_descriptors.py", line 689, in get_queryset netbox_1 | raise ValueError( netbox_1 | ValueError: 'Cable' instance needs to have a primary key value before this relationship can be used. netbox_1 | 172.19.0.1 - - [01/Feb/2023:07:13:28 +0000] "POST /api/dcim/cables/ HTTP/1.0" 500 1644 "-" "python-requests/2.24.0"
adam added the type: bugstatus: revisions needed labels 2025-12-29 20:25:45 +01:00
adam closed this issue 2025-12-29 20:25:45 +01:00
Author
Owner

@jeremystretch commented on GitHub (Feb 1, 2023):

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.

@jeremystretch commented on GitHub (Feb 1, 2023): 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.
Author
Owner

@jeremystretch commented on GitHub (Feb 7, 2023):

Closing this as no further detail has been provided.

@jeremystretch commented on GitHub (Feb 7, 2023): Closing this as no further detail has been provided.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7586