Missing default value in Object module custom fields #10274

Closed
opened 2025-12-29 21:29:15 +01:00 by adam · 6 comments
Owner

Originally created by @Etibru on GitHub (Sep 21, 2024).

Deployment Type

Self-hosted

NetBox Version

v4.1.1

Python Version

3.12

Steps to Reproduce

  1. Create a required custom field and set a default value. Choose an object like DCIM > Interface.
  2. Create a module type with a few interfaces.
  3. Create a device, create a module bay on this device.
  4. Connect a module with the module type

Expected Behavior

We should have the default value and not null. on the same way as on a device type with interfaces, when the device is created, there will be the default value on the interfaces custom field.

Observed Behavior

Interfaces added to the device have no default value in the cusom field.

Originally created by @Etibru on GitHub (Sep 21, 2024). ### Deployment Type Self-hosted ### NetBox Version v4.1.1 ### Python Version 3.12 ### Steps to Reproduce 1. Create a required custom field and set a default value. Choose an object like DCIM > Interface. 2. Create a module type with a few interfaces. 3. Create a device, create a module bay on this device. 4. Connect a module with the module type ### Expected Behavior We should have the default value and not null. on the same way as on a device type with interfaces, when the device is created, there will be the default value on the interfaces custom field. ### Observed Behavior Interfaces added to the device have no default value in the cusom field.
adam added the type: bugpending closurestatus: revisions needednetbox labels 2025-12-29 21:29:15 +01:00
adam closed this issue 2025-12-29 21:29:16 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 23, 2024):

Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.

@jeremystretch commented on GitHub (Sep 23, 2024): Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.
Author
Owner

@Etibru commented on GitHub (Sep 26, 2024):

Is any information still missing?
The bug is rather annoying, we have to run a script to correct custom fields that are set to null when they shouldn't be (must have a default value).

@Etibru commented on GitHub (Sep 26, 2024): Is any information still missing? The bug is rather annoying, we have to run a script to correct custom fields that are set to null when they shouldn't be (must have a default value).
Author
Owner

@Etibru commented on GitHub (Sep 28, 2024):

I've had a quick look at where the SET default value is missing.

HERE, when a device is created and components added, the custom field value is set to default.

               # Set default values for any applicable custom fields
                if cf_defaults := CustomField.objects.get_defaults_for_model(model):
                    component.custom_field_data = cf_defaults
                component.save()

For module bay components, you'll need to add more or less the same resonance HERE.

Something like this :

                for component in create_instances:
                    if cf_defaults := CustomField.objects.get_defaults_for_model(component_model):
                        component.custom_field_data = cf_defaults
                    post_save.send(
                        sender=component_model,
                        instance=component,
                        created=True,
                        raw=False,
                        using='default',
                        update_fields=None
                    )
@Etibru commented on GitHub (Sep 28, 2024): I've had a quick look at where the SET default value is missing. [HERE](https://github.com/netbox-community/netbox/blob/ead6e637f4aecc4717b10c71f9140c94040da264/netbox/dcim/models/devices.py#L1019C17-L1020C62), when a device is created and components added, the custom field value is set to default. ```py # Set default values for any applicable custom fields if cf_defaults := CustomField.objects.get_defaults_for_model(model): component.custom_field_data = cf_defaults component.save() ``` For module bay components, you'll need to add more or less the same resonance [HERE](https://github.com/netbox-community/netbox/blob/ead6e637f4aecc4717b10c71f9140c94040da264/netbox/dcim/models/devices.py#L1276). Something like this : ```py for component in create_instances: if cf_defaults := CustomField.objects.get_defaults_for_model(component_model): component.custom_field_data = cf_defaults post_save.send( sender=component_model, instance=component, created=True, raw=False, using='default', update_fields=None ) ```
Author
Owner

@Etibru commented on GitHub (Oct 3, 2024):

@jeremystretch do you have enough information? do I need to go into more detail? :)

@Etibru commented on GitHub (Oct 3, 2024): @jeremystretch do you have enough information? do I need to go into more detail? :)
Author
Owner

@github-actions[bot] commented on GitHub (Oct 11, 2024):

This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.

@github-actions[bot] commented on GitHub (Oct 11, 2024): This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 21, 2024):

This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.

@github-actions[bot] commented on GitHub (Oct 21, 2024): This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10274