Netbox REST API reports faulty virtual device context url #8235

Closed
opened 2025-12-29 20:34:07 +01:00 by adam · 1 comment
Owner

Originally created by @pertoft on GitHub (Jun 23, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.4.7

Python version

3.11

Steps to Reproduce

  1. Perform a GET request to get a virtual device context:
    curl -X 'GET' \ 'https://netboxtest.netic.dk/api/dcim/virtual-device-contexts/?id=9
    Response:
{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 9,
      "url": "https://netboxtest.netic.dk/api/dcim/devices/9/",
      "display": "k7404",
      "name": "k7404",
      "device": {
        "id": 1508,
        "url": "https://netboxtest.netic.dk/api/dcim/devices/1508/",
        "display": "dc4-1-a7-fg01.inf.example.dk",
        "name": "dc4-1-a7-fg01.inf.example.dk"
      },
      "identifier": null,
      "tenant": {
        "id": 404,
        "url": "https://netboxtest.netic.dk/api/tenancy/tenants/404/",
        "display": "EXAMPLE",
        "name": "EXAMPLE",
        "slug": "example"
      },
      "primary_ip": null,
      "primary_ip4": null,
      "primary_ip6": null,
      "status": "active",
      "description": "",
      "comments": "",
      "tags": [],
      "custom_fields": {},
      "created": "2023-06-23T08:10:45.356064Z",
      "last_updated": "2023-06-23T08:10:45.356085Z",
      "interface_count": 0
    }
  ]
}

It seems to me that the "url" is wrong: "url": "https://netboxtest.netic.dk/api/dcim/devices/9/" as it points at a device, and not the virtual device context endpoint.

This causes a problem when I try to delete the virtual device context, because it tries to lookup the device, and not the vdc:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
    cli.main()
  File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "/Users/pto/source/network/fortigate_hosted_vdom/NeticNetbox.py", line 114, in <module>
    n.virtual_device_context_remove(vdc,firewall)
  File "/Users/pto/source/network/fortigate_hosted_vdom/NeticNetbox.py", line 66, in virtual_device_context_remove
    vdc.delete()
  File "/opt/homebrew/lib/python3.11/site-packages/pynetbox/core/response.py", line 614, in delete
    return True if req.delete() else False
                   ^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pynetbox/core/query.py", line 372, in delete
    return self._make_call(verb="delete", data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pynetbox/core/query.py", line 240, in _make_call
    raise RequestError(req)
pynetbox.core.query.RequestError: The requested url: https://netboxtest.netic.dk/api/dcim/devices/9/ could not be found.

Expected Behavior

url should point at the virtual device context, and not at the device

Observed Behavior

url points at a dcim device

Originally created by @pertoft on GitHub (Jun 23, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.4.7 ### Python version 3.11 ### Steps to Reproduce 1. Perform a GET request to get a virtual device context: `curl -X 'GET' \ 'https://netboxtest.netic.dk/api/dcim/virtual-device-contexts/?id=9` Response: ``` { "count": 1, "next": null, "previous": null, "results": [ { "id": 9, "url": "https://netboxtest.netic.dk/api/dcim/devices/9/", "display": "k7404", "name": "k7404", "device": { "id": 1508, "url": "https://netboxtest.netic.dk/api/dcim/devices/1508/", "display": "dc4-1-a7-fg01.inf.example.dk", "name": "dc4-1-a7-fg01.inf.example.dk" }, "identifier": null, "tenant": { "id": 404, "url": "https://netboxtest.netic.dk/api/tenancy/tenants/404/", "display": "EXAMPLE", "name": "EXAMPLE", "slug": "example" }, "primary_ip": null, "primary_ip4": null, "primary_ip6": null, "status": "active", "description": "", "comments": "", "tags": [], "custom_fields": {}, "created": "2023-06-23T08:10:45.356064Z", "last_updated": "2023-06-23T08:10:45.356085Z", "interface_count": 0 } ] } ``` It seems to me that the "url" is wrong: "url": "https://netboxtest.netic.dk/api/dcim/devices/9/" as it points at a device, and not the virtual device context endpoint. This causes a problem when I try to delete the virtual device context, because it tries to lookup the device, and not the vdc: ``` Traceback (most recent call last): File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/runpy.py", line 198, in _run_module_as_main return _run_code(code, main_globals, None, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/runpy.py", line 88, in _run_code exec(code, run_globals) File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module> cli.main() File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main run() File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file runpy.run_path(target, run_name="__main__") File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path return _run_module_code(code, init_globals, run_name, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code _run_code(code, mod_globals, init_globals, File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code exec(code, run_globals) File "/Users/pto/source/network/fortigate_hosted_vdom/NeticNetbox.py", line 114, in <module> n.virtual_device_context_remove(vdc,firewall) File "/Users/pto/source/network/fortigate_hosted_vdom/NeticNetbox.py", line 66, in virtual_device_context_remove vdc.delete() File "/opt/homebrew/lib/python3.11/site-packages/pynetbox/core/response.py", line 614, in delete return True if req.delete() else False ^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/pynetbox/core/query.py", line 372, in delete return self._make_call(verb="delete", data=data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/pynetbox/core/query.py", line 240, in _make_call raise RequestError(req) pynetbox.core.query.RequestError: The requested url: https://netboxtest.netic.dk/api/dcim/devices/9/ could not be found. ``` ### Expected Behavior url should point at the virtual device context, and not at the device ### Observed Behavior url points at a dcim device
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 20:34:07 +01:00
adam closed this issue 2025-12-29 20:34:07 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Jun 23, 2023):

Seems like a copy-paste error, the url field just needs to be corrected.

70c2b358ad/netbox/dcim/api/serializers.py (L710)

@kkthxbye-code commented on GitHub (Jun 23, 2023): Seems like a copy-paste error, the url field just needs to be corrected. https://github.com/netbox-community/netbox/blob/70c2b358ad6c778344b2ee0639dab6b76f751fdc/netbox/dcim/api/serializers.py#L710
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8235