"Create & Add Another" action is broken #7961

Closed
opened 2025-12-29 20:30:31 +01:00 by adam · 4 comments
Owner

Originally created by @duckw on GitHub (Apr 29, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.5.0

Python version

3.8

Steps to Reproduce

  1. Create a custom field to apply to the device or site object. Issue observed when there is a custom text field added (no special configuration is needed).
  2. Create a new device or site but click on the "Create & Add Another" button.
    Note: I have only tested with devices and sites but the behaviour appears the same for both. The issue does not happen when the custom field is not present.

Expected Behavior

Object is created and returns to the filled out create page.

Observed Behavior

Object gets created but returns:

<class 'AttributeError'>

'str' object has no attribute 'is_cloneable'

Python version: 3.8.10
NetBox version: 3.5.0
Originally created by @duckw on GitHub (Apr 29, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.5.0 ### Python version 3.8 ### Steps to Reproduce 1. Create a custom field to apply to the device or site object. Issue observed when there is a custom text field added (no special configuration is needed). 2. Create a new device or site but click on the "Create & Add Another" button. Note: I have only tested with devices and sites but the behaviour appears the same for both. The issue does not happen when the custom field is not present. ### Expected Behavior Object is created and returns to the filled out create page. ### Observed Behavior Object gets created but returns: ``` <class 'AttributeError'> 'str' object has no attribute 'is_cloneable' Python version: 3.8.10 NetBox version: 3.5.0 ```
adam added the type: bugstatus: accepted labels 2025-12-29 20:30:31 +01:00
adam closed this issue 2025-12-29 20:30:31 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (May 1, 2023):

Thank you for your bug report, however I was not able to reproduce it. Please double check to make sure the replication steps are accurate.

@kkthxbye-code commented on GitHub (May 1, 2023): Thank you for your bug report, however I was not able to reproduce it. Please double check to make sure the replication steps are accurate.
Author
Owner

@duckw commented on GitHub (May 1, 2023):

Re-tested on the demo instance (again) and couldn't reproduce it this time.

After adding a new (text) custom field for DCIM/Site and re-testing, the issue can be reproduced.

Seems to be something to do with the presence of custom fields that stops this function from working.

@duckw commented on GitHub (May 1, 2023): Re-tested on the demo instance (again) and couldn't reproduce it this time. After adding a new (text) custom field for DCIM/Site and re-testing, the issue can be reproduced. Seems to be something to do with the presence of custom fields that stops this function from working.
Author
Owner

@kkthxbye-code commented on GitHub (May 1, 2023):

Thanks, please update the issue to include all replication steps.

It seems like something is overwriting the model instance custom_fields field. Normally custom_fields is a QuerySet of CustomFields, however when the following code is executed:

  File "/home/xxx/devel/netbox-development/netbox/netbox/views/generic/object_views.py", line 282, in post
    params = prepare_cloned_fields(obj)
  File "/home/xxx/devel/netbox-development/netbox/utilities/utils.py", line 350, in prepare_cloned_fields
    attrs = instance.clone()
  File "/home/xxx/devel/netbox-development/netbox/netbox/models/features.py", line 134, in clone
    if field.is_cloneable:

obj.custom_fields returns:

obj.custom_fields
{'testf': None}

Before the form is saved, it looks correct:

obj.custom_fields
<RestrictedQuerySet [<CustomField: Testf>]>

So it's probably something in the form that overwrites the field with a dict.

@kkthxbye-code commented on GitHub (May 1, 2023): Thanks, please update the issue to include all replication steps. It seems like something is overwriting the model instance `custom_fields` field. Normally `custom_fields` is a `QuerySet` of `CustomFields`, however when the following code is executed: ``` File "/home/xxx/devel/netbox-development/netbox/netbox/views/generic/object_views.py", line 282, in post params = prepare_cloned_fields(obj) File "/home/xxx/devel/netbox-development/netbox/utilities/utils.py", line 350, in prepare_cloned_fields attrs = instance.clone() File "/home/xxx/devel/netbox-development/netbox/netbox/models/features.py", line 134, in clone if field.is_cloneable: ``` `obj.custom_fields` returns: ``` obj.custom_fields {'testf': None} ``` Before the form is saved, it looks correct: ``` obj.custom_fields <RestrictedQuerySet [<CustomField: Testf>]> ```` So it's probably something in the form that overwrites the field with a dict.
Author
Owner

@jeremystretch commented on GitHub (May 1, 2023):

So it's probably something in the form that overwrites the field with a dict.

Spot on as always. 🙂 I've chased this down to some obsolete code in CustomFieldModelSerializer that inadvertently overwrites the custom_fields attribute on the instance during change logging. (The code itself was obsoleted years ago when we introduced the custom_field_data field, but was never removed.)

@jeremystretch commented on GitHub (May 1, 2023): > So it's probably something in the form that overwrites the field with a dict. Spot on as always. :slightly_smiling_face: I've chased this down to some [obsolete code](https://github.com/netbox-community/netbox/blob/a0f0b2943271aa41ffd901d19ad2917d845bc368/netbox/netbox/api/serializers/features.py#L25) in `CustomFieldModelSerializer` that inadvertently overwrites the `custom_fields` attribute on the instance during change logging. (The code itself was obsoleted years ago when we introduced the `custom_field_data` field, but was never removed.)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7961