Add super().clean() #4401

Closed
opened 2025-12-29 18:35:37 +01:00 by adam · 1 comment
Owner

Originally created by @candlerb on GitHub (Dec 23, 2020).

Originally assigned to: @jeremystretch on GitHub.

Proposed Changes

In forms and models which have method clean, some call super().clean() but some don't.

I'm not sure in exactly which cases these are required and not required, but I propose that super().clean() is added where missing (unless the parent class does not define this method at all)

Examples I can find in 2.10.2:

  • netbox/virtualization/models.py: VMInterface
  • netbox/secrets/forms.py: SecretForm
  • netbox/dcim/models/device_component_templates.py: PowerOutletTemplate, FrontPortTemplate
  • netbox/dcim/models/device_components.py: (multiple)
  • netbox/dcim/models/racks.py: RackGroup
  • netbox/dcim/forms.py: (multiple)
  • netbox/utilities/forms/forms.py: BulkRenameForm, ImportForm
  • netbox/users/admin.py: ObjectPermissionForm
  • netbox/ipam/forms.py: IPAddressForm
  • netbox/extras/models/models.py: Webhook, ConfigContext
  • netbox/extras/models/customfields.py: CustomFieldModel, CustomField

(There is method save too, but I've checked all those and they all call super().save(...))

Justification

Consistency and reducing likelihood of bugs due to omission - e.g. #5507

Originally created by @candlerb on GitHub (Dec 23, 2020). Originally assigned to: @jeremystretch on GitHub. ### Proposed Changes In forms and models which have method `clean`, some call `super().clean()` but some don't. I'm not sure in exactly which cases these are required and not required, but I propose that `super().clean()` is added where missing (unless the parent class does not define this method at all) Examples I can find in 2.10.2: * netbox/virtualization/models.py: VMInterface * netbox/secrets/forms.py: SecretForm * netbox/dcim/models/device_component_templates.py: PowerOutletTemplate, FrontPortTemplate * netbox/dcim/models/device_components.py: (multiple) * netbox/dcim/models/racks.py: RackGroup * netbox/dcim/forms.py: (multiple) * netbox/utilities/forms/forms.py: BulkRenameForm, ImportForm * netbox/users/admin.py: ObjectPermissionForm * netbox/ipam/forms.py: IPAddressForm * netbox/extras/models/models.py: Webhook, ConfigContext * netbox/extras/models/customfields.py: CustomFieldModel, CustomField (There is method `save` too, but I've checked all those and they all call `super().save(...)`) ### Justification Consistency and reducing likelihood of bugs due to omission - e.g. #5507
adam added the status: acceptedtype: housekeeping labels 2025-12-29 18:35:37 +01:00
adam closed this issue 2025-12-29 18:35:37 +01:00
Author
Owner

@jeremystretch commented on GitHub (Dec 28, 2020):

I'm not sure in exactly which cases these are required and not required

In some cases they aren't currently needed, but we should be consistent in our approach. This ensures that won't break if classes inherit from a new parent class with its own clean() method in the future.

@jeremystretch commented on GitHub (Dec 28, 2020): > I'm not sure in exactly which cases these are required and not required In some cases they aren't currently needed, but we should be consistent in our approach. This ensures that won't break if classes inherit from a new parent class with its own `clean()` method in the future.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4401