netbox-sync icon indicating copy to clipboard operation
netbox-sync copied to clipboard

unsupported operand type after netbox upgrade and netbox-sync update

Open Gimly86 opened this issue 8 months ago • 10 comments

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 from module.sources import instantiate_sources File "/home/SOS-DATA/netbox-sync/module/sources/init.py", line 11, in from module.sources.vmware.connection import VMWareHandler File "/home/SOS-DATA/netbox-sync/module/sources/vmware/connection.py", line 29, in from module.sources.common.source_base import SourceBase File "/home/SOS-DATA/netbox-sync/module/sources/common/source_base.py", line 22, in class SourceBase: File "/home/SOS-DATA/netbox-sync/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'

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,

Gimly86 avatar Apr 25 '25 13:04 Gimly86

Hi,

Which python version are you using?

bb-Ricardo avatar Apr 25 '25 22:04 bb-Ricardo

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 from module.sources import instantiate_sources File "/opt/netbox-sync/module/sources/init.py", line 11, in from module.sources.vmware.connection import VMWareHandler File "/opt/netbox-sync/module/sources/vmware/connection.py", line 29, in from module.sources.common.source_base import SourceBase File "/opt/netbox-sync/module/sources/common/source_base.py", line 22, in class SourceBase: File "/opt/netbox-sync/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' (.venv) [root@host netbox-sync]# python --version Python 3.9.21 (.venv) [root@host netbox-sync]# python3 --version Python 3.9.21 (.venv) [root@host netbox-sync]#

LeighBennettCP avatar May 03 '25 21:05 LeighBennettCP

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'

parlortrickss avatar May 05 '25 00:05 parlortrickss

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...

parlortrickss avatar May 05 '25 01:05 parlortrickss

Hi,

Which python version are you using?

Hi,

I use Python 3.9.2. Should I use the python version 3.10 branch ?

Regards,

Gimly86 avatar May 05 '25 15:05 Gimly86

The modifications i made to the code, worked. Sync has completed.

parlortrickss avatar May 05 '25 21:05 parlortrickss

I made the change, and it work for me too. Thanks @parlortrickss !

Gimly86 avatar May 06 '25 07:05 Gimly86

I also made the change and this fixed it for mine too. Thanks again @parlortrickss

LeighBennettCP avatar May 06 '25 15:05 LeighBennettCP

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.

bb-Ricardo avatar May 09 '25 11:05 bb-Ricardo

just need to keep this open until the new version is released. Thank you.

bb-Ricardo avatar May 27 '25 21:05 bb-Ricardo