bb-Ricardo / netbox-sync

Sync objects from VMware or redfish sources to NetBox
MIT License
274 stars 60 forks source link

TypeError: 'NoneType' object is not iterable #390

Open n-rodriguez opened 1 month ago

n-rodriguez commented 1 month ago

Hi there!

I've upgraded to netbox 4.0.1 and netbox-sync 1.6.1 and now I get this error :

Traceback (most recent call last):
  File "/data/apps/netbox/netbox-sync/netbox-sync.py", line 146, in <module>
    main()
  File "/data/apps/netbox/netbox-sync/netbox-sync.py", line 98, in main
    nb_handler.query_current_data(source.dependent_netbox_objects)
  File "/data/apps/netbox/netbox-sync/module/netbox/connection.py", line 521, in query_current_data
    self.inventory.add_object(nb_object_class, data=object_data, read_from_netbox=True)
  File "/data/apps/netbox/netbox-sync/module/netbox/inventory.py", line 176, in add_object
    new_object = object_type(data, read_from_netbox=read_from_netbox, inventory=self, source=source)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/apps/netbox/netbox-sync/module/netbox/object_classes.py", line 1178, in __init__
    super().__init__(*args, **kwargs)
  File "/data/apps/netbox/netbox-sync/module/netbox/object_classes.py", line 296, in __init__
    self.update(data=data, read_from_netbox=read_from_netbox, source=source)
  File "/data/apps/netbox/netbox-sync/module/netbox/object_classes.py", line 1199, in update
    for object_type in data.get("object_types"):
TypeError: 'NoneType' object is not iterable

Thank you!

n-rodriguez commented 1 month ago

The fix

netbox@network-tools:~/netbox-sync$ git diff
diff --git a/module/netbox/object_classes.py b/module/netbox/object_classes.py
index 7f4fda1..b7d6bfc 100644
--- a/module/netbox/object_classes.py
+++ b/module/netbox/object_classes.py
@@ -1196,6 +1196,9 @@ class NBCustomField(NetBoxObject):
         if isinstance(data.get("object_types"), str):
             data["object_types"] = [data.get("object_types")]

+        if data.get("object_types") is None:
+            data["object_types"] = []
+
         for object_type in data.get("object_types"):
             if object_type not in self.valid_object_types and read_from_netbox is False:
                 log.error(f"Invalid content type '{object_type}' for {self.name}")
n-rodriguez commented 2 weeks ago

Hi there! Any news?

bb-Ricardo commented 2 weeks ago

Sorry, currently so much other stuff going on that I barely get to do anything of that