netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Public demo: https://demo.netbox.dev
http://netboxlabs.com/oss/netbox/
Apache License 2.0
15.69k stars 2.53k forks source link

Unable to Update Interface Tags via PATCH #5239

Closed ohthateverest closed 3 years ago

ohthateverest commented 3 years ago

Environment

Steps to Reproduce

  1. Ensure Tags exist in Netbox (eg: Alcatel and BGP
  2. PATCH specifed interface with data below

    curl --location --request GET 'http://netbox-dev.contoso.com/api/dcim/interfaces/16380/' \
    --header 'Authorization: Token fe83d4e3ca6296fb681e1b821278c22ab9e0de3e' \
    --header 'Content-Type: application/json' \
    --header 'Cookie: csrftoken=Nd5JxE3OHT0WjwyNRZovQFldz7gYRQqCdExkNFNlmJul9U01kNZ9kAOda6tsWRaN' \
    --data-raw '{
    
    "tags": [
        {
            "slug": "bgp"
        },
        {
            "slug": "alcatel"
        }
    ]
    }'

Expected Behavior

Update interface to reflect selected tags. Example API Response after adding the tags via the WebUI.

{
    "id": 16380,
    "url": "http://netbox-dev.contoso.com/api/dcim/interfaces/16380/",
    "device": {
        "id": 845,
        "url": "http://netbox-dev.contoso.com/api/dcim/devices/845/",
        "name": "IPLVINEA18W-OOT-SAS-E-15",
        "display_name": "IPLVINEA18W-OOT-SAS-E-15"
    },
    "name": "1/1/4",
    "label": "",
    "type": {
        "value": "1000base-t",
        "label": "1000BASE-T (1GE)"
    },
    "enabled": true,
    "lag": null,
    "mtu": null,
    "mac_address": null,
    "mgmt_only": false,
    "description": "",
    "connected_endpoint_type": null,
    "connected_endpoint": null,
    "connection_status": null,
    "cable": null,
    "mode": null,
    "untagged_vlan": null,
    "tagged_vlans": [],
    "tags": [
        {
            "id": 39,
            "url": "http://netbox-dev.contoso.com/api/extras/tags/39/",
            "name": "Alcatel",
            "slug": "alcatel",
            "color": "9e9e9e"
        },
        {
            "id": 76,
            "url": "http://netbox-dev.contoso.com/api/extras/tags/76/",
            "name": "BGP",
            "slug": "bgp_1",
            "color": "9e9e9e"
        }
    ],
    "count_ipaddresses": 0
}

Observed Behavior

No changes are made to the interface. A 200 OK is received and the response indicates no changes are made.

{
    "id": 16380,
    "url": "http://netbox-dev.contoso.com/api/dcim/interfaces/16380/",
    "device": {
        "id": 845,
        "url": "http://netbox-dev.contoso.com/api/dcim/devices/845/",
        "name": "IPLVINEA18W-OOT-SAS-E-15",
        "display_name": "IPLVINEA18W-OOT-SAS-E-15"
    },
    "name": "1/1/4",
    "label": "",
    "type": {
        "value": "1000base-t",
        "label": "1000BASE-T (1GE)"
    },
    "enabled": true,
    "lag": null,
    "mtu": null,
    "mac_address": null,
    "mgmt_only": false,
    "description": "",
    "connected_endpoint_type": null,
    "connected_endpoint": null,
    "connection_status": null,
    "cable": null,
    "mode": null,
    "untagged_vlan": null,
    "tagged_vlans": [],
    "tags": [],
    "count_ipaddresses": 0
}
jeremystretch commented 3 years ago

Please provide the complete API request that you're sending.

ohthateverest commented 3 years ago

cURL output generated from Postman of the complete Request.

curl --location --request GET 'http://netbox-dev.contoso.com/api/dcim/interfaces/16380/' \
--header 'Authorization: Token fe83d4e3ca6296fb681e1b821278c22ab9e0de3e' \
--header 'Content-Type: application/json' \
--header 'Cookie: csrftoken=Nd5JxE3OHT0WjwyNRZovQFldz7gYRQqCdExkNFNlmJul9U01kNZ9kAOda6tsWRaN' \
--data-raw '{

    "tags": [
        {
            "slug": "bgp"
        },
        {
            "slug": "alcatel"
        }
    ]
}'
jeremystretch commented 3 years ago

curl --location --request GET

This is a GET request. You need to make a PATCH request.

ohthateverest commented 3 years ago

Sorry posted the wrong example.

curl --location --request PATCH 'http://netbox-dev.contoso.com/api/dcim/interfaces/16380/' \
--header 'Authorization: Token fe83d4e3ca6296fb681e1b821278c22ab9e0de3e' \
--header 'Content-Type: application/json' \
--header 'Cookie: csrftoken=Nd5JxE3OHT0WjwyNRZovQFldz7gYRQqCdExkNFNlmJul9U01kNZ9kAOda6tsWRaN' \
--data-raw '{

    "tags": [
        {
            "slug": "bgp"
        },
        {
            "slug": "alcatel"
        }
    ]
}'

Response is

{
    "id": 16380,
    "url": "http://netbox-dev.contoso.com/api/dcim/interfaces/16380/",
    "device": {
        "id": 845,
        "url": "http://netbox-dev.contoso.com/api/dcim/devices/845/",
        "name": "IPLVINEA18W-OOT-SAS-E-15",
        "display_name": "IPLVINEA18W-OOT-SAS-E-15"
    },
    "name": "1/1/4",
    "label": "",
    "type": {
        "value": "1000base-t",
        "label": "1000BASE-T (1GE)"
    },
    "enabled": true,
    "lag": null,
    "mtu": null,
    "mac_address": null,
    "mgmt_only": false,
    "description": "",
    "connected_endpoint_type": null,
    "connected_endpoint": null,
    "connection_status": null,
    "cable": null,
    "mode": null,
    "untagged_vlan": null,
    "tagged_vlans": [],
    "tags": [],
    "count_ipaddresses": 0
}
jeremystretch commented 3 years ago

I'm not able to reproduce this on v2.9.7

ohthateverest commented 3 years ago

Trying it again and it works now, Gonna chalk this up to maybe something weird being cached. Sorry for chasing ghosts.