Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'NoneType' object is not iterable #390

Open
n-rodriguez opened this issue May 15, 2024 · 1 comment
Open

TypeError: 'NoneType' object is not iterable #390

n-rodriguez opened this issue May 15, 2024 · 1 comment

Comments

@n-rodriguez
Copy link
Contributor

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
Copy link
Contributor Author

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}")

kipp-lucas added a commit to heinrich-kipp-werk/NetBox-Sync-vCenter that referenced this issue May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant