prepare_cloned_fields() should check for cloning support on model #10701

Closed
opened 2025-12-29 21:34:57 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Jan 27, 2025).

Originally assigned to: @arthanson on GitHub.

Deployment Type

NetBox Cloud

NetBox Version

v4.2.2

Python Version

3.10

Steps to Reproduce

  1. Define a clone() method on a plugin model, returning None.
  2. Install the plugin.
  3. Attempt to view an instance of that model.

Expected Behavior

The object should render successfully.

Observed Behavior

An unhandled AttributeError exception is raised:

'NoneType' object has no attribute 'items'

This is because NetBox expects the clone() method, if defined on a model, to return a set of attributes suitable for pre-populating the creation form for the model. However, a plugin author might want to introduce a clone() method for unrelated reasons.

NetBox should inspect the model and attempt to call clone() only for models which inherit from CloningMixin.

Originally created by @jeremystretch on GitHub (Jan 27, 2025). Originally assigned to: @arthanson on GitHub. ### Deployment Type NetBox Cloud ### NetBox Version v4.2.2 ### Python Version 3.10 ### Steps to Reproduce 1. Define a `clone()` method on a plugin model, returning None. 2. Install the plugin. 3. Attempt to view an instance of that model. ### Expected Behavior The object should render successfully. ### Observed Behavior An unhandled `AttributeError` exception is raised: > 'NoneType' object has no attribute 'items' This is because NetBox expects the `clone()` method, if defined on a model, to return a set of attributes suitable for pre-populating the creation form for the model. However, a plugin author might want to introduce a `clone()` method for unrelated reasons. NetBox should inspect the model and attempt to call `clone()` only for models which inherit from [`CloningMixin`](https://github.com/netbox-community/netbox/blob/57fa1dd18dbaa5c927ceae37b5879044b9f154e1/netbox/netbox/models/features.py#L115).
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:34:57 +01:00
adam closed this issue 2025-12-29 21:34:57 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10701