From 5c21555aa504f97060ec3e2d30f9f758782a4dbe Mon Sep 17 00:00:00 2001 From: Harm Geerts Date: Mon, 26 Jun 2023 14:07:29 +0200 Subject: [PATCH] Fix #12983 bulk edit of M2M fields when nothing is selected Partially revert 41c92483a0b9b820dd0ca0c43c6c6d6e560043ed to restore bulk edit with m2m fields. The m2m cleaned_data yields a empty queryset when nothing is selected. By setting the m2m relation unless set null is checked even when nothing is selected the m2m relation is always cleared. This commit only sets the m2m relation when a selection is made. --- netbox/netbox/views/generic/bulk_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/netbox/views/generic/bulk_views.py b/netbox/netbox/views/generic/bulk_views.py index e66e79a7a44..35caa31b362 100644 --- a/netbox/netbox/views/generic/bulk_views.py +++ b/netbox/netbox/views/generic/bulk_views.py @@ -551,7 +551,7 @@ def _update_objects(self, form, request): for name, m2m_field in m2m_fields.items(): if name in form.nullable_fields and name in nullified_fields: getattr(obj, name).clear() - else: + elif form.cleaned_data[name]: getattr(obj, name).set(form.cleaned_data[name]) # Add/remove tags