Cable turns into bugged state after edited via API #8923

Closed
opened 2025-12-29 20:42:54 +01:00 by adam · 8 comments
Owner

Originally created by @salfers on GitHub (Dec 6, 2023).

NetBox version

v3.6.6

Python version

3.9

Steps to Reproduce

  1. Create a cable between two interfaces (see screenshot under 'Observed Behaviour')
  2. Use pynetbox to interact with the cable in the following way. The data state after the operation should be exactly the same as before.
	cable = next(nb.dcim.cables.filter(id=27))
	iface = cable.serialize()['a_terminations'][0]
	# disconnect one end
	cable.update({'a_terminations': []})
	# connect it again
	nb.dcim.cable_terminations.create({
		'cable': cable.id, 'cable_end': 'A',
		'termination_type': "dcim.interface", 'termination_id': iface
	})

Expected Behavior

Everything should look as it did before:
grafik

Observed Behavior

Interfaces view shows totally incorrect data (in case of XE1) or nothing being connected (in case of XE2):
grafik
Viewing the cable itself shows nothing wrong:
grafik

Originally created by @salfers on GitHub (Dec 6, 2023). ### NetBox version v3.6.6 ### Python version 3.9 ### Steps to Reproduce 1. Create a cable between two interfaces (see screenshot under 'Observed Behaviour') 2. Use pynetbox to interact with the cable in the following way. The data state after the operation should be exactly the same as before. ```py cable = next(nb.dcim.cables.filter(id=27)) iface = cable.serialize()['a_terminations'][0] # disconnect one end cable.update({'a_terminations': []}) # connect it again nb.dcim.cable_terminations.create({ 'cable': cable.id, 'cable_end': 'A', 'termination_type': "dcim.interface", 'termination_id': iface }) ``` ### Expected Behavior Everything should look as it did before: ![grafik](https://github.com/netbox-community/netbox/assets/97662717/00a41a5b-cc4b-43ea-bcf7-bc5f0d8190bd) ### Observed Behavior Interfaces view shows totally incorrect data (in case of XE1) or nothing being connected (in case of XE2): ![grafik](https://github.com/netbox-community/netbox/assets/97662717/dfda7d38-605c-4ab4-87cf-71810dd13523) Viewing the cable itself shows nothing wrong: ![grafik](https://github.com/netbox-community/netbox/assets/97662717/033b9cff-a32a-4bd7-9a24-20a4fddd008b)
adam added the type: bugtopic: cabling labels 2025-12-29 20:42:54 +01:00
adam closed this issue 2025-12-29 20:42:55 +01:00
Author
Owner

@salfers commented on GitHub (Dec 6, 2023):

Reproduction code without use of pynetbox:

cable = requests.get(f"{HOST}/api/dcim/cables/29/", headers={"Authorization": f"Token {TOKEN}"}).json()
iface = cable['a_terminations'][0]['object_id']
# disconnect one end
requests.patch(f"{HOST}/api/dcim/cables/29/", headers={"Authorization": f"Token {TOKEN}"}, json={
	'a_terminations': []
})
# connect it again
requests.post(f"{HOST}/api/dcim/cable-terminations/", headers={"Authorization": f"Token {TOKEN}"}, json={
	'cable': cable['id'], 'cable_end': 'A',
	'termination_type': "dcim.interface", 'termination_id': iface
})
@salfers commented on GitHub (Dec 6, 2023): Reproduction code without use of pynetbox: ```py cable = requests.get(f"{HOST}/api/dcim/cables/29/", headers={"Authorization": f"Token {TOKEN}"}).json() iface = cable['a_terminations'][0]['object_id'] # disconnect one end requests.patch(f"{HOST}/api/dcim/cables/29/", headers={"Authorization": f"Token {TOKEN}"}, json={ 'a_terminations': [] }) # connect it again requests.post(f"{HOST}/api/dcim/cable-terminations/", headers={"Authorization": f"Token {TOKEN}"}, json={ 'cable': cable['id'], 'cable_end': 'A', 'termination_type': "dcim.interface", 'termination_id': iface }) ```
Author
Owner

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

The a_terminations and b_terminations fields on CableSerializer should be read-only. Cable terminations should be added and removed using the /api/dcim/cable-terminations/ endpoint. See below.

@jeremystretch commented on GitHub (Dec 6, 2023): ~The `a_terminations` and `b_terminations` fields on CableSerializer should be read-only. Cable terminations should be added and removed using the `/api/dcim/cable-terminations/` endpoint.~ See [below](https://github.com/netbox-community/netbox/issues/14445#issuecomment-1869652339).
Author
Owner

@salfers commented on GitHub (Dec 6, 2023):

I see, thanks for the hint.

What maybe confused me is that in the cable JSON the id of the termination is not immediately visible, and I need this id to delete the termination (right?):
grafik

@salfers commented on GitHub (Dec 6, 2023): I see, thanks for the hint. What maybe confused me is that in the cable JSON the id of the termination is not immediately visible, and I need this id to delete the termination (right?): ![grafik](https://github.com/netbox-community/netbox/assets/97662717/4c370e32-02f0-414b-b533-dde3b20e7280)
Author
Owner

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

What maybe confused me is that in the cable JSON the id of the termination is not immediately visible, and I need this id to delete the termination (right?):

Yeah you're right, the objects listed in a_terminations should each include the ID of the termination record itself in addition to the ID of the terminated object.

Edit: I've opened #14606 to explore this further.

@jeremystretch commented on GitHub (Dec 6, 2023): > What maybe confused me is that in the cable JSON the id of the termination is not immediately visible, and I need this id to delete the termination (right?): Yeah you're right, the objects listed in `a_terminations` should each include the ID of the termination record itself in addition to the ID of the terminated object. Edit: I've opened #14606 to explore this further.
Author
Owner

@jeremystretch commented on GitHub (Dec 26, 2023):

Just had the chance to dig more into this. What I said above is incorrect; a_terminations and b_terminations can be modified on the cable instance (and are used to set terminations when creating a cable).

I'm actually not able to reproduce this on NetBox v3.6.7. Starting with a cable (ID 1) with its A side connected to a circuit termination, I first clear a_terminations:

curl -X PATCH \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
http://netbox:8000/api/dcim/cables/1/ \
--data '{"a_terminations": []}'

Then I create a new termination to replace it:

curl -X POST \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
http://netbox:8000/api/dcim/cable-terminations/ \
--data '{"cable": 1, "cable_end": "A", "termination_type": "circuits.circuittermination", "termination_id": 15}'

The cable is now back to its original state as intended.

Could you please provide reproduction instructions without using pynetbox (just raw curl commands as above)? This will help us determine if it's a bug in the pynetbox client.

@jeremystretch commented on GitHub (Dec 26, 2023): Just had the chance to dig more into this. What I said above is incorrect; `a_terminations` and `b_terminations` _can_ be modified on the cable instance (and are used to set terminations when creating a cable). I'm actually not able to reproduce this on NetBox v3.6.7. Starting with a cable (ID 1) with its A side connected to a circuit termination, I first clear `a_terminations`: ``` curl -X PATCH \ -H "Authorization: Token $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ http://netbox:8000/api/dcim/cables/1/ \ --data '{"a_terminations": []}' ``` Then I create a new termination to replace it: ``` curl -X POST \ -H "Authorization: Token $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ http://netbox:8000/api/dcim/cable-terminations/ \ --data '{"cable": 1, "cable_end": "A", "termination_type": "circuits.circuittermination", "termination_id": 15}' ``` The cable is now back to its original state as intended. Could you please provide reproduction instructions without using pynetbox (just raw `curl` commands as above)? This will help us determine if it's a bug in the pynetbox client.
Author
Owner

@jeremystretch commented on GitHub (Dec 26, 2023):

I do see an issue with recalculating the path (which might be a separate bug), but the directly connected cable peer(s) are set as expected.

@jeremystretch commented on GitHub (Dec 26, 2023): I do see an issue with recalculating the path (which might be a separate bug), but the directly connected cable peer(s) are set as expected.
Author
Owner

@salfers commented on GitHub (Dec 28, 2023):

Thanks for looking at this.
As far as I remember the issue was only the incorrect display of the cable path and the actual data (/api/dcim/cables/NN/) was fine.

@salfers commented on GitHub (Dec 28, 2023): Thanks for looking at this. As far as I remember the issue was only the incorrect display of the cable path and the actual data (`/api/dcim/cables/NN/`) was fine.
Author
Owner

@jeremystretch commented on GitHub (May 28, 2024):

Closing this out as further steps have not been identified. If this continues to be an issue, please submit a new bug report with detailed steps to reproduce the issue on the latest NetBox release.

@jeremystretch commented on GitHub (May 28, 2024): Closing this out as further steps have not been identified. If this continues to be an issue, please submit a new bug report with detailed steps to reproduce the issue on the latest NetBox release.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8923