Skip to content

Commit

Permalink
Fixes #88 - Invalid URL with empty filter()
Browse files Browse the repository at this point in the history
Raise a ValueError when kwargs for filter() is empty to keep a uniform API and prevent the issues seen in issue #88.
  • Loading branch information
zmoody committed Nov 3, 2018
1 parent 71cc521 commit 053e857
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pynetbox/lib/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ def get(self, *args, **kwargs):
if len(filter_lookup) == 0:
return None
else:
raise ValueError('get() returned more than one result.')
raise ValueError(
'get() returned more than one result.'
'Perhaps use filter() or all() instead.'
)

req = Request(
key=key,
Expand Down Expand Up @@ -217,9 +220,14 @@ def filter(self, *args, **kwargs):
>>>
"""

if len(args) > 0:
if args:
kwargs.update({'q': args[0]})

if not kwargs:
raise ValueError(
'filter must be passed kwargs. Perhaps use all().'
)

req = Request(
filters=kwargs,
base=self.url,
Expand Down

0 comments on commit 053e857

Please # to comment.