Skip to content

When parsing response values, lists should also be turned into records. #92

@ebusto

Description

@ebusto

As dictionaries are automatically turned into records, it would be handy if the same happened to lists, when an attribute is actually multiple records.

As a quick and dirty test, this seems to work OK:

mana:pynetbox ebusto$ git diff
diff --git a/pynetbox/lib/response.py b/pynetbox/lib/response.py
index 852f853..0baf67d 100644
--- a/pynetbox/lib/response.py
+++ b/pynetbox/lib/response.py
@@ -162,6 +162,10 @@ class Record(object):
                 self._add_cache((k, v))
             else:
                 self._add_cache((k, v.copy()))
+
+            if isinstance(v, list):
+                v = map(lambda i: self.default_ret(i, api_kwargs=self.api_kwargs), v)
+
             setattr(self, k, v)
 
     def _compare(self):

Then it's records all the way down!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions