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

Fix broken __eq__ implementation of Netbox stub class #3226

Merged
merged 3 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3225.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix spurious crashing when loading some Netmap layer 3 views
6 changes: 2 additions & 4 deletions python/nav/netmap/stubs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
18 changes: 18 additions & 0 deletions tests/unittests/netmap/stubs_test.py
Original file line number Diff line number Diff line change
@@ -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
Loading