pynetbox
pynetbox copied to clipboard
Get filtering on non existent device_id raises RequestError when it should return None
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.
>>> interface = nb.dcim.interfaces.get(name="Ethernet9", device_id=99)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.10/site-packages/pynetbox/core/endpoint.py", line 161, in get
ret = next(resp, None)
File "/usr/local/lib/python3.10/site-packages/pynetbox/core/response.py", line 127, in __next__
next(self.response), self.endpoint.api, self.endpoint
File "/usr/local/lib/python3.10/site-packages/pynetbox/core/query.py", line 291, in get
req = self._make_call(add_params=add_params)
File "/usr/local/lib/python3.10/site-packages/pynetbox/core/query.py", line 258, in _make_call
raise RequestError(req)
pynetbox.core.query.RequestError: The request failed with code 400 Bad Request: {'device_id': ['Select a valid choice. 99 is not one of the available choices.']}
Expected Behavior
If the device id doesn't exist then None should be returned, as it would for any other get call.
>>> interface = nb.dcim.interfaces.get(name="Ethernet9", device_id=99)
>>> interface == None
True
Observed Behavior
Seems that device_id is being used as a choice when it should not be.