Skip to content

Commit 6cf4508

Browse files
author
Zach Moody
committed
Fix up DetailEndpoint.list() to continue returning lists
1 parent 6016d97 commit 6cf4508

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

pynetbox/core/endpoint.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,12 @@ def list(self, **kwargs):
413413
req = Request(**self.request_kwargs).get(add_params=kwargs)
414414

415415
if self.custom_return:
416-
for i in req:
417-
yield self.custom_return(
416+
return [
417+
self.custom_return(
418418
i, self.parent_obj.endpoint.api, self.parent_obj.endpoint
419419
)
420+
for i in req
421+
]
420422
return req
421423

422424
def create(self, data=None):

pynetbox/core/query.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ def get(self, add_params=None):
346346
first_run = False
347347
for i in req["results"]:
348348
yield i
349+
elif isinstance(req, list):
350+
self.count = len(req)
351+
for i in req:
352+
yield i
349353
else:
350354
self.count = len(req)
351355
yield req

pynetbox/models/dcim.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424

2525
class TraceableRecord(Record):
2626
def trace(self):
27-
req = list(
28-
Request(
29-
key=str(self.id) + "/trace",
30-
base=self.endpoint.url,
31-
token=self.api.token,
32-
session_key=self.api.session_key,
33-
http_session=self.api.http_session,
34-
).get()
35-
)[0]
27+
req = Request(
28+
key=str(self.id) + "/trace",
29+
base=self.endpoint.url,
30+
token=self.api.token,
31+
session_key=self.api.session_key,
32+
http_session=self.api.http_session,
33+
).get()
3634
uri_to_obj_class_map = {
3735
"dcim/cables": Cables,
3836
"dcim/front-ports": FrontPorts,

tests/integration/test_dcim.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def init(self, request, rack):
100100

101101
def test_get_elevation(self):
102102
test = self.fixture.elevation.list()
103-
assert next(test)
103+
assert test
104+
assert isinstance(test, list)
104105

105106

106107
class TestManufacturer(BaseTest):

0 commit comments

Comments
 (0)