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 SeedDB edit netbox regression #2761

Merged
merged 3 commits into from Nov 24, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions python/nav/web/seeddb/page/netbox/edit.py
Expand Up @@ -56,20 +56,16 @@ def log_netbox_change(account, old, new):

# Compare changes from old to new
attribute_list = [
'read_only',
'read_write',
'category',
'ip',
'room',
'organization',
'snmp_version',
]
LogEntry.compare_objects(
account,
old,
new,
attribute_list,
censored_attributes=['read_only', 'read_write'],
)


Expand Down
14 changes: 12 additions & 2 deletions tests/integration/seeddb_test.py
Expand Up @@ -6,8 +6,7 @@
from mock import MagicMock

from nav.models.manage import Netbox, Room
from nav.models.profiles import Account, AlertProfile
from nav.web.seeddb.page.netbox.edit import netbox_edit
from nav.web.seeddb.page.netbox.edit import netbox_edit, log_netbox_change
from nav.web.seeddb.utils.delete import dependencies

import pytest
Expand Down Expand Up @@ -58,3 +57,14 @@ def test_dependencies_no_whitelist(netbox):
deps = dependencies(qs, [])
assert Netbox.objects.get(pk=netbox.pk)
assert deps == {}


def test_log_netbox_change_should_not_crash(admin_account, netbox):
"""Regression test to ensure this function doesn't try to access removed or
invalid attributes on Netbox.
"""
old = Netbox.objects.get(id=netbox.id)
new = netbox
new.category_id = "OTHER"

assert log_netbox_change(admin_account, old, new) is None