bb-Ricardo / netbox-sync

Sync objects from VMware or redfish sources to NetBox
MIT License
290 stars 65 forks source link

TypeError: 'NoneType' object is not iterable #390

Closed n-rodriguez closed 4 weeks ago

n-rodriguez commented 6 months 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 6 months 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 5 months ago

Hi there! Any news?

bb-Ricardo commented 5 months ago

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

bb-Ricardo commented 1 month ago

This should be fixed with #415 in next-release would you be able to try it out?