Repository: digitalocean/pynetbox
Pull request #345 (2021-04-02 21:48:56)

Fix threaded returns


Patch:
diff --git a/pynetbox/core/query.py b/pynetbox/core/query.py
index 592b847..c1e126d 100644
--- a/pynetbox/core/query.py
+++ b/pynetbox/core/query.py
@@ -130,7 +130,7 @@ class Request(object):
         base,
         http_session,
         filters=None,
-        limit=0,
+        limit=None,
         key=None,
         token=None,
         private_key=None,
@@ -307,6 +307,8 @@ class Request(object):
             endpoint.
         """
 
+        if not add_params and self.limit is not None:
+            add_params = {"limit": self.limit}
         req = self._make_call(add_params=add_params)
         if isinstance(req, dict) and req.get("results") is not None:
             self.count = req["count"]
@@ -323,7 +325,8 @@ class Request(object):
                         ret.extend(req["results"])
                     else:
                         self.concurrent_get(ret, page_size, page_offsets)
-                return ret
+                for i in ret:
+                    yield i
             first_run = True
             for i in req["results"]:
                 yield i


Test patch:
diff --git a/tests/test_circuits.py b/tests/test_circuits.py
index 5212b9c..4d90759 100644
--- a/tests/test_circuits.py
+++ b/tests/test_circuits.py
@@ -34,7 +34,7 @@ class Generic(object):
                     "http://localhost:8000/api/{}/{}/".format(
                         self.app, self.name.replace("_", "-")
                     ),
-                    params={},
+                    params={"limit": 0},
                     json=None,
                     headers=HEADERS,
                 )
@@ -51,7 +51,7 @@ class Generic(object):
                     "http://localhost:8000/api/{}/{}/".format(
                         self.app, self.name.replace("_", "-")
                     ),
-                    params={"name": "test"},
+                    params={"name": "test", "limit": 0},
                     json=None,
                     headers=HEADERS,
                 )
diff --git a/tests/test_tenancy.py b/tests/test_tenancy.py
index f9db902..9a40f35 100644
--- a/tests/test_tenancy.py
+++ b/tests/test_tenancy.py
@@ -35,7 +35,7 @@ class Generic(object):
                     "http://localhost:8000/api/{}/{}/".format(
                         self.app, self.name.replace("_", "-")
                     ),
-                    params={},
+                    params={"limit": 0},
                     json=None,
                     headers=HEADERS,
                 )
@@ -52,7 +52,7 @@ class Generic(object):
                     "http://localhost:8000/api/{}/{}/".format(
                         self.app, self.name.replace("_", "-")
                     ),
-                    params={"name": "test"},
+                    params={"name": "test", "limit": 0},
                     json=None,
                     headers=HEADERS,
                 )
diff --git a/tests/test_users.py b/tests/test_users.py
index af410c7..da8daad 100644
--- a/tests/test_users.py
+++ b/tests/test_users.py
@@ -35,7 +35,7 @@ class Generic(object):
                     "http://localhost:8000/api/{}/{}/".format(
                         self.app, self.name.replace("_", "-")
                     ),
-                    params={},
+                    params={"limit": 0},
                     json=None,
                     headers=HEADERS,
                 )
@@ -52,7 +52,7 @@ class Generic(object):
                     "http://localhost:8000/api/{}/{}/".format(
                         self.app, self.name.replace("_", "-")
                     ),
-                    params={"name": "test"},
+                    params={"name": "test", "limit": 0},
                     json=None,
                     headers=HEADERS,
                 )
diff --git a/tests/test_virtualization.py b/tests/test_virtualization.py
index 6a50929..ec8aac6 100644
--- a/tests/test_virtualization.py
+++ b/tests/test_virtualization.py
@@ -35,7 +35,7 @@ class Generic(object):
                     "http://localhost:8000/api/{}/{}/".format(
                         self.app, self.name.replace("_", "-")
                     ),
-                    params={},
+                    params={"limit": 0},
                     json=None,
                     headers=HEADERS,
                 )
@@ -52,7 +52,7 @@ class Generic(object):
                     "http://localhost:8000/api/{}/{}/".format(
                         self.app, self.name.replace("_", "-")
                     ),
-                    params={"name": "test"},
+                    params={"name": "test", "limit": 0},
                     json=None,
                     headers=HEADERS,
                 )