Connected Endpoint is not updated when Cable is updated #2455

Closed
opened 2025-12-29 18:19:00 +01:00 by adam · 6 comments
Owner

Originally created by @VictorPavlushin on GitHub (Mar 12, 2019).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.6.6
  • NetBox version: 2.5.8

Steps to Reproduce

  1. Create device name: sw1
  2. Create interface on sw1 name sw_port1
  3. Create device name srv1
  4. Create interfaces on srv1 with the names: srv_port1 and srv_port2
  5. Create cable connection sw1:sw_port1 -> srv1:srv_port1
  6. Using the PUT or PATCH method, change the connection from sw1:sw_port1 -> srv1: srv_port1 to sw1:sw_port1 -> srv1:srv_port2
    sw_port1 id: 10925
    srv_port1 id: 10929
    srv_port2 id: 10930
    cable id: 688
    curl -X PUT "http://netbox/api/dcim/cables/688/" -H "accept: application/json" -H "Content-Type: application/json" -H "X-CSRFToken: ...." -d "{ \"termination_a_type\": \"dcim.interface\", \"termination_a_id\": 10930, \"termination_b_type\": \"dcim.interface\", \"termination_b_id\": 10925}"

Expected Behavior

  1. All information on the 688 cable from the srv_port1 port will be removed
  2. There will be full information about the connection of cable 688 on the port srv_port2

Observed Behavior

  1. The cable information from the srv_port1 port has not been removed:
curl ..... http://netbox/api/dcim/interfaces/10929/
{
    "id": 10929,
    "device": {
        "id": 3133,
        "url": "http://netbox/api/dcim/devices/3133/",
        "name": "srv1",
        "display_name": "srv1"
    },
    "name": "srv_port1",
..........
    "connected_endpoint_type": "dcim.interface",
    "connected_endpoint": {
        "id": 10925,
        "url": "http://netbox/api/dcim/interfaces/10925/",
        "device": {
            "id": 3132,
            "url": "http://netbox/api/dcim/devices/3132/",
            "name": "sw1",
            "display_name": "sw1"
        },
        "name": "sw_port1",
        "cable": 688,
        "connection_status": {
            "value": true,
            "label": "Connected"
        }
    },
    "connection_status": {
        "value": true,
        "label": "Connected"
    },
    "cable": {
        "id": 688,
        "url": "http://netbox/api/dcim/cables/688/",
        "label": ""
    },
......
}
  1. Not full information on connecting cable 688 to port srv_port2
curl ... http://netbox/api/dcim/interfaces/10930/
{
    "id": 10930,
    "device": {
        "id": 3133,
        "url": "http://netbox/api/dcim/devices/3133/",
        "name": "srv1",
        "display_name": "srv1"
    },
    "name": "srv_port2",
.............
    "connected_endpoint_type": null,
    "connected_endpoint": null,
    "connection_status": null,
    "cable": {
        "id": 688,
        "url": "http://netbox/api/dcim/cables/688/",
        "label": ""
    },
..............
}

PS
But in the cable information is all correct:

curl  ..... http://netbox/api/dcim/cables/688/
{
    "id": 688,
    "termination_a_type": "dcim.interface",
    "termination_a_id": 10930,
    "termination_a": {
        "id": 10930,
        "url": "http://netbox/api/dcim/interfaces/10930/",
        "device": {
            "id": 3133,
            "url": "http://netbox/api/dcim/devices/3133/",
            "name": "srv1",
            "display_name": "srv1"
        },
        "name": "srv_port2",
        "cable": 688,
        "connection_status": null
    },
    "termination_b_type": "dcim.interface",
    "termination_b_id": 10925,
    "termination_b": {
        "id": 10925,
        "url": "http://netbox/api/dcim/interfaces/10925/",
        "device": {
            "id": 3132,
            "url": "http://netbox/api/dcim/devices/3132/",
            "name": "sw1",
            "display_name": "sw1"
        },
        "name": "sw_port1",
        "cable": 688,
        "connection_status": {
            "value": true,
            "label": "Connected"
        }
    },
    "type": null,
    "status": {
        "value": true,
        "label": "Connected"
    },
    "label": "",
    "color": "",
    "length": null,
    "length_unit": null
}
Originally created by @VictorPavlushin on GitHub (Mar 12, 2019). Originally assigned to: @jeremystretch on GitHub. ### Environment * Python version: 3.6.6 * NetBox version: 2.5.8 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a wrapper like pynetbox. --> ### Steps to Reproduce 1. Create device name: sw1 2. Create interface on sw1 name sw_port1 3. Create device name srv1 4. Create interfaces on srv1 with the names: srv_port1 and srv_port2 5. Create cable connection sw1:sw_port1 -> srv1:srv_port1 6. Using the PUT or PATCH method, change the connection from sw1:sw_port1 -> srv1: srv_port1 to sw1:sw_port1 -> srv1:srv_port2 sw_port1 id: 10925 srv_port1 id: 10929 srv_port2 id: 10930 cable id: 688 ` curl -X PUT "http://netbox/api/dcim/cables/688/" -H "accept: application/json" -H "Content-Type: application/json" -H "X-CSRFToken: ...." -d "{ \"termination_a_type\": \"dcim.interface\", \"termination_a_id\": 10930, \"termination_b_type\": \"dcim.interface\", \"termination_b_id\": 10925}"` ### Expected Behavior 1) All information on the 688 cable from the srv_port1 port will be removed 2) There will be full information about the connection of cable 688 on the port srv_port2 ### Observed Behavior 1) The cable information from the srv_port1 port has not been removed: ``` curl ..... http://netbox/api/dcim/interfaces/10929/ { "id": 10929, "device": { "id": 3133, "url": "http://netbox/api/dcim/devices/3133/", "name": "srv1", "display_name": "srv1" }, "name": "srv_port1", .......... "connected_endpoint_type": "dcim.interface", "connected_endpoint": { "id": 10925, "url": "http://netbox/api/dcim/interfaces/10925/", "device": { "id": 3132, "url": "http://netbox/api/dcim/devices/3132/", "name": "sw1", "display_name": "sw1" }, "name": "sw_port1", "cable": 688, "connection_status": { "value": true, "label": "Connected" } }, "connection_status": { "value": true, "label": "Connected" }, "cable": { "id": 688, "url": "http://netbox/api/dcim/cables/688/", "label": "" }, ...... } ``` 2) Not full information on connecting cable 688 to port srv_port2 ``` curl ... http://netbox/api/dcim/interfaces/10930/ { "id": 10930, "device": { "id": 3133, "url": "http://netbox/api/dcim/devices/3133/", "name": "srv1", "display_name": "srv1" }, "name": "srv_port2", ............. "connected_endpoint_type": null, "connected_endpoint": null, "connection_status": null, "cable": { "id": 688, "url": "http://netbox/api/dcim/cables/688/", "label": "" }, .............. } ``` PS But in the cable information is all correct: ``` curl ..... http://netbox/api/dcim/cables/688/ { "id": 688, "termination_a_type": "dcim.interface", "termination_a_id": 10930, "termination_a": { "id": 10930, "url": "http://netbox/api/dcim/interfaces/10930/", "device": { "id": 3133, "url": "http://netbox/api/dcim/devices/3133/", "name": "srv1", "display_name": "srv1" }, "name": "srv_port2", "cable": 688, "connection_status": null }, "termination_b_type": "dcim.interface", "termination_b_id": 10925, "termination_b": { "id": 10925, "url": "http://netbox/api/dcim/interfaces/10925/", "device": { "id": 3132, "url": "http://netbox/api/dcim/devices/3132/", "name": "sw1", "display_name": "sw1" }, "name": "sw_port1", "cable": 688, "connection_status": { "value": true, "label": "Connected" } }, "type": null, "status": { "value": true, "label": "Connected" }, "label": "", "color": "", "length": null, "length_unit": null } ```
adam added the type: bugstatus: accepted labels 2025-12-29 18:19:00 +01:00
adam closed this issue 2025-12-29 18:19:00 +01:00
Author
Owner

@DanSheps commented on GitHub (Mar 15, 2019):

Looked into this a little bit, looks like there are a couple of things going on here..

First, when a cable is created, it saves the "connected interface" into the interfaces table for that specific interface.

When a cable is updated, that interface is suppose to be updated by a signal, however it cannot because, at least in my testing, I found there was a duplicate foreign key from the old value.

We cod do away with this caching, and instead run direct calls to get_path_endpoints(), however that presents another problem, which is we would most likely need to run several database queries for each cable to get endpoints. This could have a negative performance impact.

Another way, is to possibly add in a pre_save and have that remove the endpoint from the model first, but I think @jeremystretch and @lampwins should weigh in first if we even want to do this. I am not 100% familiar with DJango signals.

@DanSheps commented on GitHub (Mar 15, 2019): Looked into this a little bit, looks like there are a couple of things going on here.. First, when a cable is created, it saves the "connected interface" into the interfaces table for that specific interface. When a cable is updated, that interface is suppose to be updated by a signal, however it cannot because, at least in my testing, I found there was a duplicate foreign key from the old value. We cod do away with this caching, and instead run direct calls to get_path_endpoints(), however that presents another problem, which is we would most likely need to run several database queries for each cable to get endpoints. This could have a negative performance impact. Another way, is to possibly add in a pre_save and have that remove the endpoint from the model first, but I think @jeremystretch and @lampwins should weigh in first if we even want to do this. I am not 100% familiar with DJango signals.
Author
Owner

@jeremystretch commented on GitHub (Apr 8, 2019):

I think the most reasonable approach is to disallow modifying the endpoint of an existing cable. This was never part of the intended workflow; the cable should be deleted and a new one created with the desired endpoints.

@jeremystretch commented on GitHub (Apr 8, 2019): I think the most reasonable approach is to disallow modifying the endpoint of an existing cable. This was never part of the intended workflow; the cable should be deleted and a new one created with the desired endpoints.
Author
Owner

@steffann commented on GitHub (Nov 1, 2019):

FYI: I can fix this as part of #3633.

@steffann commented on GitHub (Nov 1, 2019): FYI: I can fix this as part of #3633.
Author
Owner

@DanSheps commented on GitHub (Nov 1, 2019):

@steffann How are you proposing to fix it? If you do fix it, it would be best to have it part of a separate commit.

@DanSheps commented on GitHub (Nov 1, 2019): @steffann How are you proposing to fix it? If you do fix it, it would be best to have it part of a separate commit.
Author
Owner

@jeremystretch commented on GitHub (Nov 1, 2019):

Agreed. Bugs need to be addressed individually and not conflated with separate feature work. This allows us to clearly track how they are fixed (or not fixed) over time.

@jeremystretch commented on GitHub (Nov 1, 2019): Agreed. Bugs need to be addressed individually and not conflated with separate feature work. This allows us to clearly track how they are fixed (or not fixed) over time.
Author
Owner

@steffann commented on GitHub (Nov 1, 2019):

This bug is a side effect of limitations in the current way connected endpoints are implemented. My suggestion is to improve the endpoint handling to be more flexible, and then this bug won't be an issue anymore.

There have been multiple bugs that are caused by architectural limitations. Let's fix the architecture instead of paying whack-a-mole with the resulting bugs.

@steffann commented on GitHub (Nov 1, 2019): This bug is a side effect of limitations in the current way connected endpoints are implemented. My suggestion is to improve the endpoint handling to be more flexible, and then this bug won't be an issue anymore. There have been multiple bugs that are caused by architectural limitations. Let's fix the architecture instead of paying whack-a-mole with the resulting bugs.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2455