netbox-community / netbox-bgp

NetBox plugin for BGP related objects documentation
Apache License 2.0
240 stars 46 forks source link

URL error when to trying save / update objects via API using pynetbox #203

Open rvtipper opened 2 weeks ago

rvtipper commented 2 weeks ago

NetBox version netbox: 4.0.8 netbox-bgp: 0.13.2 pynetbox: 7.4.0

Describe the bug When using pynetbox and I try to use the .save() or .update() methods on an object via the API I get an error that the URL could not be found. The URL that it complains about seems to be missing 'plugins' in the path

To Reproduce Using pynetbox fetch an object via API, make a change and then try .save() method on the object.

prefixlist = nb_dev.plugins.bgp.prefix_list.get(name='PL_TEST')
prefixlist.name = 'PL_TESTAPI'
pprint(dict(prefixlist))
prefixlist.save()
{'comments': '',
 'custom_fields': {},
 'description': '',
 'display': 'PL_TEST',
 'family': 'ipv4',
 'id': 198,
 'name': 'PL_TESTAPI',
 'tags': [],
 'url': 'http://localhost:6999/plugins/bgp/prefix-list/198/'}

Traceback (most recent call last):
  File "/home/rvt/scripts/netbox-mover/testing.py", line 26, in <module>
    prefixlist.save()
  File "/home/rvt/scripts/netbox-mover/.venv/lib/python3.10/site-packages/pynetbox/core/response.py", line 571, in save
    if req.patch(updates):
  File "/home/rvt/scripts/netbox-mover/.venv/lib/python3.10/site-packages/pynetbox/core/query.py", line 398, in patch
    return self._make_call(verb="patch", data=data)
  File "/home/rvt/scripts/netbox-mover/.venv/lib/python3.10/site-packages/pynetbox/core/query.py", line 260, in _make_call
    raise RequestError(req)
pynetbox.core.query.RequestError: The requested url: http://localhost:6999/api/bgp/prefix-list/198/ could not be found.

Same result if I try for example prefixlist.update({"name": "PL_TEST_API", "display": "PL_TEST_API"})

Expected behavior For the changes to be saved. This works ok for me in netbox 3.7.4 and netbox-bgp 0.12.1, same pynetbox version.

Additional context This happens for me on policies and sessions as well. I can update just fine using requests and PATCH, however wondering if something changed recently which breaks the URL pynetbox is using.

Also I notice the url attribute on the returned object is missing 'api' in the path compared to other netbox objects

thanks!

cruse1977 commented 2 weeks ago

Really good spot, fix awaiting review