unsupported operand type after netbox upgrade and netbox-sync update
Hello,
I updated my Netbox from 3.4.x to 4.1.11 andnetbox-sync to 1.8.0 via GIT, and when I launche the command, I have this error :
Traceback (most recent call last):
File "/home/SOS-DATA/netbox-sync/netbox-sync.py", line 23, in
I dos this :
- delete cache => same error
- remove netbox-sync and reinstall netbox-sync from fresh install => same error.
Do you have an idea to solve my problem, please ?
Thanks in advance.
Best regards,
Hi,
Which python version are you using?
I have the same Issue. I have followed the installation guide and attempted to run the .py for the first time. I'm using Rocky Linux 9 and the default Python 3.9. Trying to run with the debug option gives the same results.
[root@host netbox-sync]# . .venv/bin/activate
(.venv) [root@host netbox-sync]# /opt/netbox-sync/netbox-sync.py -n
Traceback (most recent call last):
File "/opt/netbox-sync/netbox-sync.py", line 23, in
We are running Python 3.6.8 and get the same error. v170 runs fine but v180 does not. I have tried re-using the venv from 170 and also creating a fresh one for 180 and still get the same error
Traceback (most recent call last): File "/lfs/global/apps/netbox-sync-main-latest/netbox-sync.py", line 23, in <module> from module.sources import instantiate_sources File "/lfs/global/apps/netbox-sync-main-180/module/sources/__init__.py", line 11, in <module> from module.sources.vmware.connection import VMWareHandler File "/lfs/global/apps/netbox-sync-main-180/module/sources/vmware/connection.py", line 29, in <module> from module.sources.common.source_base import SourceBase File "/lfs/global/apps/netbox-sync-main-180/module/sources/common/source_base.py", line 22, in <module> class SourceBase: File "/lfs/global/apps/netbox-sync-main-180/module/sources/common/source_base.py", line 182, in SourceBase def return_longest_matching_prefix_for_ip(self, ip_to_match=None, site_name=None) -> NBPrefix|None: TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
Ok so it looks like you have added type hints with operator | which only comes into play from version 3.10.0. That being the case i added from typing import Union,Optional
I modified the following lines in module/sources/common/source_base.py:
Line 182:
def return_longest_matching_prefix_for_ip(self, ip_to_match=None, site_name=None) -> NBPrefix|None:
to
def return_longest_matching_prefix_for_ip(self, ip_to_match=None, site_name=None) -> Optional[NBPrefix]:
and
Line 719:
def add_vlan_group(self, vlan_data, vlan_site, vlan_cluster) -> NBVLAN | dict:
to
def add_vlan_group(self, vlan_data, vlan_site, vlan_cluster) -> Union[NBVLAN ,dict]:
This should work for python versions <3.10.0, not sure if will work for above as well.
I am currently running the sync script, it will take a few hours before i know if this change works, but it hasnt bombed out immediately like it was prior to the changes.
I am unfamiliar with making a pull request to submit a fix if this works...
Hi,
Which python version are you using?
Hi,
I use Python 3.9.2. Should I use the python version 3.10 branch ?
Regards,
The modifications i made to the code, worked. Sync has completed.
I made the change, and it work for me too. Thanks @parlortrickss !
I also made the change and this fixed it for mine too. Thanks again @parlortrickss
Hi,
sorry I was busy lately and haven't had time looking into this issue. Thank you so much for figuring this out. I just pushed a commit to the development branch which adds @parlortrickss suggested changes.
just need to keep this open until the new version is released. Thank you.