diff --git a/changelog.d/3225.fixed.md b/changelog.d/3225.fixed.md new file mode 100644 index 0000000000..8c01d58522 --- /dev/null +++ b/changelog.d/3225.fixed.md @@ -0,0 +1 @@ +Fix spurious crashing when loading some Netmap layer 3 views diff --git a/python/nav/netmap/stubs/__init__.py b/python/nav/netmap/stubs/__init__.py index 9e8da80aca..77daf391f4 100644 --- a/python/nav/netmap/stubs/__init__.py +++ b/python/nav/netmap/stubs/__init__.py @@ -36,10 +36,8 @@ def __repr__(self): def __key(self): return self.sysname - # Yes we know we access private variable - # pylint: disable=W0212 - def __eq__(self, i): - return self.__key() == i.__key() + def __eq__(self, value): + return self.sysname == getattr(value, "sysname", None) def __hash__(self): return hash(self.__key()) diff --git a/tests/unittests/netmap/stubs_test.py b/tests/unittests/netmap/stubs_test.py new file mode 100644 index 0000000000..0b5307fbaa --- /dev/null +++ b/tests/unittests/netmap/stubs_test.py @@ -0,0 +1,18 @@ +from nav.netmap.stubs import Netbox +from nav.models import manage + + +class TestNetboxEqWithNonStubValues: + def test_when_value_is_orm_model_with_same_sysname_it_should_return_true(self): + localhost = manage.Netbox(sysname='localhost') + stub = Netbox() + stub.sysname = localhost.sysname + assert stub == localhost + + def test_when_value_is_orm_model_with_different_sysname_it_should_return_false( + self, + ): + localhost = manage.Netbox(sysname='localhost') + stub = Netbox() + stub.sysname = "stubhost" + assert stub != localhost