Skip to content

Commit

Permalink
replace None with 'null' in query paramters
Browse files Browse the repository at this point in the history
Requests skips parameters that are None.
Map 'null' string to None python type for a more native coding
  • Loading branch information
doc-sheet authored and ds committed Aug 28, 2023
1 parent 53eaca6 commit 5b10650
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pynetbox/core/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,9 @@ def filter(self, *args, **kwargs):
offset = kwargs.pop("offset") if "offset" in kwargs else None
if limit == 0 and offset is not None:
raise ValueError("offset requires a positive limit value")
filters = {x: y if y is not None else "null" for x, y in kwargs.items()}
req = Request(
filters=kwargs,
filters=filters,
base=self.url,
token=self.token,
http_session=self.api.http_session,
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def test_filter_invalid_pagination_args(self):
with self.assertRaises(ValueError) as _:
test_obj.filter(offset=1)

def test_filter_replace_none_with_null(self):
api = Mock(base_url="http://localhost:8000/api")
app = Mock(name="test")
test_obj = Endpoint(api, app, "test")
test = test_obj.filter(name=None, id=0)

self.assertEqual(test.request.filters, {"name": "null", "id": 0})

def test_all_invalid_pagination_args(self):

api = Mock(base_url="http://localhost:8000/api")
Expand Down

0 comments on commit 5b10650

Please sign in to comment.