Open pthmas opened 1 month ago
Works here:
>>> pynetbox.__version__
'7.3.3'
>>> netbox.status()["netbox-version"]
'3.7.3'
>>> interface = netbox.dcim.interfaces.get(name="Loopback", device_id=1222)
>>> interface
Loopback
>>>
It does work for me when the device_id
exist but not when it doesn't. Does it also work for you if the device_id
doesn't exist?
Oh, sorry, I misread your issue.
When you test the API you see that pynetbox
just returns what NetBox returns:
$ curl -i -H "Content-Type: application/json" -H "Authorization: Token xxxxxxxxxxx" \
https://netbox.example.com/api/dcim/interfaces/?device_id=99
HTTP/2 400
api-version: 3.7
...
{"device_id":["Select a valid choice. 99 is not one of the available choices."]}
$
So if you feel this is an error, then raise an issue in the NetBox repository.
Thanks for your input.
I only raised this issue because we have a test in our stack using the exact query I used in the example, this query used to return None
and now returns BadRequestError
. This change happened when I both upgraded, pynetbox and Netbox. I'll consider opening an issue on the Netbox repo then!
pynetbox version
v7.3.3
NetBox version
v3.7.8
Python version
3.10
Steps to Reproduce
When trying to get an interface while filtering on device_id, if the device_id doesn't exist a 400 BadRequest response is being raised.
Expected Behavior
If the device id doesn't exist then
None
should be returned, as it would for any other get call.Observed Behavior
Seems that
device_id
is being used as a choice when it should not be.