From 7dc9b4d91dd36288e62253ef9db8ac3e719b2674 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 12 Aug 2026 15:24:01 +0200 Subject: [PATCH] fix: handle NetBox device form clean result --- README.md | 2 +- netbox_utilities/__init__.py | 2 +- netbox_utilities/rack_width.py | 3 ++- netbox_utilities/tests/test_rack_width.py | 25 +++++++++++++++++++++++ pyproject.toml | 2 +- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9f2940d..33a07b1 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Release-Tag oder ein bestimmter Commit verwendet werden: ```bash /opt/netbox/venv/bin/pip install --upgrade --force-reinstall \ - "git+https://git.mrblake.cc/MrBlake/Netbox-Utilities.git@v0.8.4" + "git+https://git.mrblake.cc/MrBlake/Netbox-Utilities.git@v0.8.5" ``` Alternativ kann hinter dem `@` die vollständige Commit-ID stehen. diff --git a/netbox_utilities/__init__.py b/netbox_utilities/__init__.py index e7e108e..1f00a7a 100644 --- a/netbox_utilities/__init__.py +++ b/netbox_utilities/__init__.py @@ -1,6 +1,6 @@ from netbox.plugins import PluginConfig, get_plugin_config -__version__ = "0.8.4" +__version__ = "0.8.5" class NetBoxUtilitiesConfig(PluginConfig): diff --git a/netbox_utilities/rack_width.py b/netbox_utilities/rack_width.py index 80bc123..c6aacb2 100644 --- a/netbox_utilities/rack_width.py +++ b/netbox_utilities/rack_width.py @@ -389,7 +389,8 @@ def _install_device_form(): self.fields = reordered def clean(self): - cleaned_data = super().clean() + super().clean() + cleaned_data = self.cleaned_data try: width, horizontal_position = normalize_width_position( cleaned_data.get("utilities_rack_width"), diff --git a/netbox_utilities/tests/test_rack_width.py b/netbox_utilities/tests/test_rack_width.py index ad8e64a..dbf85c3 100644 --- a/netbox_utilities/tests/test_rack_width.py +++ b/netbox_utilities/tests/test_rack_width.py @@ -114,6 +114,31 @@ class RackWidthTest(SimpleTestCase): self.assertLess(html.index(width), html.index(horizontal_position)) self.assertLess(html.index(horizontal_position), html.index(latitude)) + def test_bound_device_form_clean_handles_netbox_clean_returning_none(self): + from dcim.models import Device + from netbox.registry import registry + + edit_view = next(view["view"] for view in registry["views"]["dcim"]["device"] if view["name"] == "edit") + object_type = SimpleNamespace(pk=1, model_class=lambda: Device) + with ( + patch("core.models.ObjectType.objects.get_for_model", return_value=object_type), + patch( + "django.contrib.contenttypes.models.ContentType.objects.get_for_model", + return_value=object_type, + ), + patch("extras.models.CustomField.objects.get_for_model", return_value=[]), + patch( + "netbox_utilities.runtime._get_database_settings", + return_value={"tenant_required": True}, + ), + ): + form = edit_view.form(data={}) + # NetBox 4.6.7's CheckLastUpdatedMixin.clean() updates + # self.cleaned_data but deliberately returns None. + with patch.object(form, "_post_clean"): + self.assertFalse(form.is_valid()) + self.assertIsInstance(form.cleaned_data, dict) + @staticmethod def _anonymous_request(): request = RequestFactory().get("/dcim/devices/1/edit/") diff --git a/pyproject.toml b/pyproject.toml index 66cc23c..da65daf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "netbox-utilities" -version = "0.8.4" +version = "0.8.5" description = "Navigation, tenant utilities, partial-width rack devices, bulk uploads, and rack reordering for NetBox 4.6" readme = "README.md" requires-python = ">=3.12"