Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom fields default value on Objects from modules are not set #17820

Closed
Etibru opened this issue Oct 21, 2024 · 1 comment · Fixed by #18084
Closed

Custom fields default value on Objects from modules are not set #17820

Etibru opened this issue Oct 21, 2024 · 1 comment · Fixed by #18084
Assignees
Labels
netbox severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@Etibru
Copy link

Etibru commented Oct 21, 2024

Deployment Type

Self-hosted

Triage priority

N/A

NetBox Version

v4.1.4

Python Version

3.12

Steps to Reproduce

  1. Create a required custom field and set a default value. Choose an object like DCIM > Interface.
{
    "id": 8,
    "display": "My cf",
    "object_types": [
        "dcim.interface"
    ],
    "type": {
        "value": "text",
        "label": "Text"
    },
    "related_object_type": null,
    "data_type": "string",
    "name": "My_CF",
    "label": "",
    "group_name": "",
    "description": "",
    "required": true,
    "unique": false,
    "search_weight": 1000,
    "filter_logic": {
        "value": "loose",
        "label": "Loose"
    },
    "ui_visible": {
        "value": "always",
        "label": "Always"
    },
    "ui_editable": {
        "value": "yes",
        "label": "Yes"
    },
    "is_cloneable": false,
    "default": "default_value",
    "related_object_filter": null,
    "weight": 100,
    "validation_minimum": null,
    "validation_maximum": null,
    "validation_regex": "",
    "choice_set": null,
    "comments": "",
}

2.Create a module type with a few interfaces.
17295182262847603361889833276334

  1. Create a device, create a module bay on this device.
    17295182378236963683433093075664

  2. Connect a module with the module type
    17295182497146946160325110780536

Now, we have the interfaces from the type module that have been added to the device.
17295182632186578896907287261420

And if we see an Interface:
17295182817146530767661734069473

We can see that the default value has not been set.

"custom_fields": {
"My_CF": null
},
Note that in devices with device_type, interface custom fields (for example) are set to the default value

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 that are created when the module is connected to a device, the default values of custom fields are not set to their default values.

@Etibru Etibru added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Oct 21, 2024
@jeremystretch jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: medium Results in substantial degraded or broken functionality for specfic workflows and removed status: needs triage This issue is awaiting triage by a maintainer labels Oct 22, 2024
@jeremystretch jeremystretch added the netbox label Nov 1, 2024 — with Linear
@Etibru
Copy link
Author

Etibru commented Nov 5, 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
                    )

Maybe there's something better to do

@bctiemann bctiemann self-assigned this Nov 22, 2024
@bctiemann bctiemann added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Nov 22, 2024
jeremystretch pushed a commit that referenced this issue Dec 11, 2024
…ted module components (#18084)

* Store default values from custom fields on newly created module components

* Invert if/for lines to avoid repetition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
netbox severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
3 participants