Custom fields don't get updated when field name changes #4663

Closed
opened 2025-12-29 19:19:17 +01:00 by adam · 1 comment
Owner

Originally created by @heiko-ma on GitHub (Mar 16, 2021).

NetBox version

v2.10.6

Python version

3.6

Steps to Reproduce

  1. Create custom field in the admin gui, e.g. 'testing', the settings don't matter
  2. Set a custom field value on a suitable device
  3. Change the custom field name in the admin gui, e.g. testing_cf
  4. Try to update the value of the custom field on the device

Expected Behavior

The value gets correctly updated and no errors occur.

Observed Behavior

An error is thrown:
"Unknown field name 'testing' in custom field data."

I did some research on why this error happens. Here's what I found out:

  • When a device with custom fields is edited, the custom_field_data is written to a column in the table of the corresponding device type, e.g. dcim_device -> Column name: custom_field_data
  • If you change the name of the custom field afterwards, it doesn't get updated in the tables where it's used because there is no logical relation between the declaration of the custom fields in the admin gui and the values of the fields itself.

I'm unsure if this system is intended but it easily can lead to data inconsistency when you edit the name of custom fields (you have to edit the values in the database afterwards).

There are two options I can think of to fix this:

  • add an additional json key to the custom_field_data field, which represents the id of the custom field definition entry, this way you can link between those two values
  • every time a custom field definition is changed, every item in netbox is checked for consistency
Originally created by @heiko-ma on GitHub (Mar 16, 2021). ### NetBox version v2.10.6 ### Python version 3.6 ### Steps to Reproduce 1. Create custom field in the admin gui, e.g. 'testing', the settings don't matter 2. Set a custom field value on a suitable device 3. Change the custom field name in the admin gui, e.g. testing_cf 4. Try to update the value of the custom field on the device ### Expected Behavior The value gets correctly updated and no errors occur. ### Observed Behavior An error is thrown: "Unknown field name 'testing' in custom field data." I did some research on why this error happens. Here's what I found out: - When a device with custom fields is edited, the custom_field_data is written to a column in the table of the corresponding device type, e.g. **dcim_device** -> Column name: **custom_field_data** - If you change the name of the custom field afterwards, it doesn't get updated in the tables where it's used because there is no logical relation between the declaration of the custom fields in the admin gui and the values of the fields itself. I'm unsure if this system is intended but it easily can lead to data inconsistency when you edit the name of custom fields (you have to edit the values in the database afterwards). There are two options I can think of to fix this: - add an additional json key to the **custom_field_data** field, which represents the id of the custom field definition entry, this way you can link between those two values - every time a custom field definition is changed, every item in netbox is checked for consistency
adam added the type: bugstatus: duplicate labels 2025-12-29 19:19:17 +01:00
adam closed this issue 2025-12-29 19:19:17 +01:00
Author
Owner

@jeremystretch commented on GitHub (Mar 16, 2021):

Thank you for submitting this issue, however it appears that this topic has already been raised. Please see issue #5652 for further discussion.

@jeremystretch commented on GitHub (Mar 16, 2021): Thank you for submitting this issue, however it appears that this topic has already been raised. Please see issue #5652 for further discussion.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4663