-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Bulk edit of models with M2M fields can clear the M2M field #12983
Comments
Hello, I'm facing this issue too... Also and for clarification, you mention the untagged_vlan field (excepted / observed behavior section). However, as you mentioned, this issue occurs with m2m fields, so with tagged_vlans (not untagged_vlan). My proposal to fix this issue : --- a/netbox/netbox/views/generic/bulk_views.py
+++ b/netbox/netbox/views/generic/bulk_views.py
@@ -551,7 +551,7 @@ class BulkEditView(GetReturnURLMixin, BaseMultiObjectView):
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 name in form.changed_data:
getattr(obj, name).set(form.cleaned_data[name]) |
@netopsab Would you like to submit a pr? |
why not ... :) |
…lected Partially revert 41c9248 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.
The change proposed by @netopsab does not fix the problem. The bulk edit form always includes m2m fields in the cleaned_data. Otherwise the old code would trigger a |
@netopsab is checking against changed_data not cleaned_data. His method is consistent with our rchecking in other areas. Both approaches are equally valid. |
Partially revert 41c9248 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 version
v3.5.4 and tested on develop
Python version
3.10
Steps to Reproduce
Expected Behavior
The untagged_vlans should remain unchanged if none are selected and set null is unchecked.
Observed Behavior
The untagged_vlans are removed from the interface.
Caused by https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/views/generic/bulk_views.py#L554-L555
In 41c9248 the truthy check on the m2m queryset was removed. Django querysets evaluate to False if the queryset is empty.
The text was updated successfully, but these errors were encountered: