Fixes #20776: Add changelog message to bulk rename process#22100
Fixes #20776: Add changelog message to bulk rename process#22100
Conversation
|
@claude /review Only report on issues of potential concern; we don't need commentary on anything that doesn't require further consideration. |
|
Claude finished @jnovinger's task in 4m 19s —— View job Code Review
Issues of Concern1.
|
|
@claude /review Only report on issues of potential concern; we don't need commentary on anything that doesn't require further consideration.
Out of scope, will file a follow up housekeeping issue for this.
Added a comment indicating why this is safe.
Added. |
|
Claude finished @jnovinger's task in 3m 24s —— View job Code Review
Both addressed issues check out. One minor residual concern below.
|
Move BulkRenameForm to netbox.forms.bulk_rename to enable ChangelogMessageMixin inheritance without circular imports. Wire up _changelog_message on objects before save in BulkRenameView, with conditional field removal for models that don't support change logging.
- Add explanatory comment on base_fields.pop() safety - Add skipTest guard for models without ChangeLoggingMixin
d8ba7c3 to
5e2dbde
Compare
pheus
left a comment
There was a problem hiding this comment.
Thanks for explaining the circular import! That helped a lot while reviewing.
That said, I don’t think we should move BulkRenameForm out of utilities.forms in a patch release. That changes an existing import path that plugins/custom code may already rely on, e.g. from utilities.forms import BulkRenameForm.
It also changes the current separation between generic utility forms in utilities and NetBox model-specific forms in netbox. I’m not opposed to moving or reorganizing these forms, but I think that should wait for a release where breaking import-path changes are allowed.
The cleanest patch-release-safe alternative I can think of is to keep utilities.forms.BulkRenameForm as the generic form and add a NetBox-specific wrapper, similar to the existing bulk edit pattern:
class NetBoxModelBulkRenameForm(ChangelogMessageMixin, BulkRenameForm):
passI’d also suggest making BulkRenameView.form an explicit extension point, while still injecting the pk field dynamically from the view. The pk field depends on the scoped queryset, so I think it should remain view-owned rather than becoming part of the generic form.
For example:
class BulkRenameView(GetReturnURLMixin, BaseMultiObjectView):
"""
An extendable view for renaming objects in bulk.
Attributes:
field_name: The name of the object attribute for which the value is being updated (defaults to "name")
form: Optional base form class used for the rename operation
"""
field_name = 'name'
template_name = 'generic/bulk_rename.html'
filterset = None
form = None
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
base_form = self.form
if base_form is None:
base_form = (
NetBoxModelBulkRenameForm
if issubclass(self.queryset.model, ChangeLoggingMixin)
else BulkRenameForm
)
class _Form(base_form):
pk = ModelMultipleChoiceField(
queryset=self.queryset,
widget=MultipleHiddenInput()
)
self.form = _FormThis keeps utilities.forms.BulkRenameForm generic and backwards-compatible, avoids importing ChangelogMessageMixin into utilities.forms, and removes the need to mutate base_fields to strip changelog_message for models that do not support change logging.
One thing to watch: VMInterfaceBulkRenameView and VirtualDiskBulkRenameView already set form, but BulkRenameView currently overwrites it, so those form classes have effectively been unused. If we make form supported now, those two should either be updated to inherit from the new NetBox-specific bulk rename form, or removed/cleaned up separately if they are not needed.
Fixes: #20776
Adds changelog message support to the bulk rename view, bringing it in line with bulk edit, bulk delete, and bulk import.
Changes
BulkRenameFormnow inherits fromChangelogMessageMixin, adding an optional changelog message fieldBulkRenameViewsetsobj._changelog_messagebefore save (both MPTT and non-MPTT paths)BulkRenameView.__init__for models that don't support change loggingtest_bulk_rename_objects_with_changelog_messagein the standard view test mixinNo template changes were needed:
render_form.htmlalready handlesmeta_fieldsrendering.Form relocation
BulkRenameFormwas moved fromutilities/forms/forms.pytonetbox/forms/bulk_rename.py. This was necessary becauseutilities/forms/forms.pyloads early in Django's boot chain (viaextras/models→utilities/fields→utilities/forms). AddingChangelogMessageMixinas a parent there creates a circular import since the mixin's module importsextras.models, which hasn't finished loading at that point. The new location innetbox/forms/loads after the app registry is populated, so the import works cleanly.