Probleb with add local_config_context on an existing device #3727

Closed
opened 2025-12-29 18:30:48 +01:00 by adam · 4 comments
Owner

Originally created by @nazarko-es on GitHub (May 27, 2020).

Environment

  • Python version: 3.8
  • NetBox version: 2.8.4

Steps to Reproduce

  1. Upload device with local_context_data field. For example my field:
    {
    "bgp_neighbors": [
    {
    "as": "65000",
    "neighbor": "169.254.0.1"
    },
    {
    "as": "65001",
    "neighbor": "169.254.0.2"
    }
    ],
    "track": [
    "10.10.0.251/32",
    "10.10.0.252/32"
    ],
    "vlans": []
    }
  2. Get local_context_data in python script and append local_context_data['vlans']. For example:

device = nb.dcim.devices.get(name='mydevice')
local_context = device.local_context_data
vlans_list = [{'vid': 1, 'name': 'vlan1'}, {'vid': 2, 'name': 'vlan2'}]
for vlan in vlans_list:
local_context['vlans'].append({"vid": vlan['vid'], 'name': vlan['name']})
device.update(dict(local_context_data=local_context))

Expected Behavior

Update local_context_data field

Observed Behavior

Local_context_data doesn't update

If i don't use "get" from netbox, but set local_context in my code, it's work. For example:

device = nb.dcim.devices.get(name='pd100-elf-025')
new_local_context = {
"bgp_neighbors": [
{
"as": "65000",
"neighbor": "169.254.0.1"
},
{
"as": "65001",
"neighbor": "169.254.0.2"
}
],
"track": [
"10.10.0.251/32",
"10.10.0.252/32"
],
"vlans": []
}

vlans_list = [{'vid': 1, 'name': 'vlan1'}, {'vid': 2, 'name': 'vlan2'}]
for vlan in vlans_list:
new_local_context['vlans'].append({"vid": vlan['vid'], 'name': vlan['name']})
device.update(dict(local_context_data=new_local_context))

Originally created by @nazarko-es on GitHub (May 27, 2020). ### Environment * Python version: 3.8 * NetBox version: 2.8.4 ### Steps to Reproduce 1. Upload device with local_context_data field. For example my field: { "bgp_neighbors": [ { "as": "65000", "neighbor": "169.254.0.1" }, { "as": "65001", "neighbor": "169.254.0.2" } ], "track": [ "10.10.0.251/32", "10.10.0.252/32" ], "vlans": [] } 2. Get local_context_data in python script and append local_context_data['vlans']. For example: device = nb.dcim.devices.get(name='mydevice') local_context = device.local_context_data vlans_list = [{'vid': 1, 'name': 'vlan1'}, {'vid': 2, 'name': 'vlan2'}] for vlan in vlans_list: local_context['vlans'].append({"vid": vlan['vid'], 'name': vlan['name']}) device.update(dict(local_context_data=local_context)) ### Expected Behavior Update local_context_data field ### Observed Behavior Local_context_data doesn't update If i don't use "get" from netbox, but set local_context in my code, it's work. For example: device = nb.dcim.devices.get(name='pd100-elf-025') new_local_context = { "bgp_neighbors": [ { "as": "65000", "neighbor": "169.254.0.1" }, { "as": "65001", "neighbor": "169.254.0.2" } ], "track": [ "10.10.0.251/32", "10.10.0.252/32" ], "vlans": [] } vlans_list = [{'vid': 1, 'name': 'vlan1'}, {'vid': 2, 'name': 'vlan2'}] for vlan in vlans_list: new_local_context['vlans'].append({"vid": vlan['vid'], 'name': vlan['name']}) device.update(dict(local_context_data=new_local_context))
adam closed this issue 2025-12-29 18:30:48 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 27, 2020):

Per the bug report template:

If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox.

Please update the body of your issue to reflect the actual REST API calls that are being made, and which can be replicated by someone else to reproduce the bug. (If this is not possible, the bug lies within the client, not NetBox.)

@jeremystretch commented on GitHub (May 27, 2020): Per the bug report template: > If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. Please update the body of your issue to reflect the actual REST API calls that are being made, and which can be replicated by someone else to reproduce the bug. (If this is not possible, the bug lies within the client, not NetBox.)
Author
Owner

@nazarko-es commented on GitHub (Jun 3, 2020):

How can i reconstruct the raw HTTP request? Should I use python request module instead pynetbox?

@nazarko-es commented on GitHub (Jun 3, 2020): How can i reconstruct the raw HTTP request? Should I use python request module instead pynetbox?
Author
Owner

@jeremystretch commented on GitHub (Jun 8, 2020):

@nazarko-es curl is typically used for simplicity. Take a look at some other bug reports relating to the REST API; there are plenty of examples.

@jeremystretch commented on GitHub (Jun 8, 2020): @nazarko-es `curl` is typically used for simplicity. Take a look at some other bug reports relating to the REST API; there are plenty of examples.
Author
Owner

@jeremystretch commented on GitHub (Jun 15, 2020):

Closing due to inactivity. Please request reopening if you can provide an example API request using curl that will reproduce the reported issue on the current stable release.

@jeremystretch commented on GitHub (Jun 15, 2020): Closing due to inactivity. Please request reopening if you can provide an example API request using `curl` that will reproduce the reported issue on the current stable release.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3727