Modules not showing in UI #8976

Closed
opened 2025-12-29 20:43:32 +01:00 by adam · 6 comments
Owner

Originally created by @josh9730 on GitHub (Dec 16, 2023).

Deployment Type

Self-hosted

NetBox Version

3.6.7

Python Version

3.10

Steps to Reproduce

  • Script to create two new devices using a DeviceType with 4 ModuleBays defined
  • The devices will have an Object custom field defined to create a one-to-one bi-directional link between the devices
  • The script creates & full_clean/saves the device, then creates & full_clean/saves the Object custom field addition

Expected Behavior

The two devices should have 4 ModuleBays each as well as the custom field linking the two devices.

Observed Behavior

  • When viewing the new devices in the UI, the 4 ModuleBays are not viewable, but they are present in the API and in nbshell.
  • If I try to create ModuleBays through the UI, I get an error "Module bay with this Device and Name already exists". If I then hit Cancel, I get taken to a screen that shows the Modules, but does not show the actual Modules tab. After leaving this page, I cannot browse back to it
    Screenshot 2023-12-15 at 4 57 03 PM

When manually creating the same DeviceTypes and the custom link, or when creating modular devices that do not get the custom link, the issue does not occur (i.e. the module bays are present in the UI). No issues observed with the custom field itself.

Originally created by @josh9730 on GitHub (Dec 16, 2023). ### Deployment Type Self-hosted ### NetBox Version 3.6.7 ### Python Version 3.10 ### Steps to Reproduce - Script to create two new devices using a DeviceType with 4 ModuleBays defined - The devices will have an Object custom field defined to create a one-to-one bi-directional link between the devices - The script creates & full_clean/saves the device, then creates & full_clean/saves the Object custom field addition ### Expected Behavior The two devices should have 4 ModuleBays each as well as the custom field linking the two devices. ### Observed Behavior - When viewing the new devices in the UI, the 4 ModuleBays are not viewable, but they are present in the API and in nbshell. - If I try to create ModuleBays through the UI, I get an error "Module bay with this Device and Name already exists". If I then hit Cancel, I get taken to a screen that shows the Modules, but does not show the actual Modules tab. After leaving this page, I cannot browse back to it ![Screenshot 2023-12-15 at 4 57 03 PM](https://github.com/netbox-community/netbox/assets/49131939/9016597d-24fb-4bed-9a57-0d05d5484f28) When manually creating the same DeviceTypes and the custom link, or when creating modular devices that do not get the custom link, the issue does not occur (i.e. the module bays are present in the UI). No issues observed with the custom field itself.
adam added the type: bugstatus: revisions needed labels 2025-12-29 20:43:33 +01:00
adam closed this issue 2025-12-29 20:43:33 +01:00
Author
Owner

@jsenecal commented on GitHub (Dec 18, 2023):

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.

@jsenecal commented on GitHub (Dec 18, 2023): 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

@jeremystretch commented on GitHub (Dec 26, 2023):

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.

@jeremystretch commented on GitHub (Dec 26, 2023): 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.
Author
Owner

@wz4 commented on GitHub (Jan 7, 2024):

I have encountered this issue as well. Are you calling clean & save method for the device more than once in your script? That's what I have narrowed the problem down to in mine. Module Bays tab show up fine otherwise.

@wz4 commented on GitHub (Jan 7, 2024): I have encountered this issue as well. Are you calling clean & save method for the device more than once in your script? That's what I have narrowed the problem down to in mine. Module Bays tab show up fine otherwise.
Author
Owner

@wz4 commented on GitHub (Jan 7, 2024):

Here is a script to reproduce the problem. Make sure to update the module_bay variable as needed.


from dcim.choices import DeviceStatusChoices
from dcim.models import Device, DeviceRole, DeviceType, Module, ModuleBay, ModuleType, Site
from extras.scripts import *


class CreateSwitch(Script):

    class Meta:
        name = "Create Device"
        description = "Create a device and associated interfaces"
        scheduling_enabled = False

    device_name = StringVar(
        label="Device Name",
        required=True,
    )
    device_type = ObjectVar(
        label='Device Type',
        model=DeviceType
    )
    module_type = ObjectVar(
        label="Module Type",
        model=ModuleType
    )
    status = ChoiceVar(
        label="Status",
        choices=DeviceStatusChoices
    )
    role = ObjectVar(
        label='Device Role',
        model=DeviceRole,
    )
    site = ObjectVar(
        label='Site',
        model=Site,
    )


    def run(self, data, commit):
        module_bay = "slot-1"

        try:
            # Create Device
            device = Device(
                name=data['device_name'],
                device_type=data['device_type'],
                role=data["role"],
                site=data["site"],
            )
            device.full_clean()
            device.save()
            self.log_success(f"Created new device: {device}")

            # Create Module
            module = Module(
                device=device,
                module_bay=ModuleBay.objects.get(device=device, name=module_bay),
                module_type=data['module_type']
            )
            module.full_clean()
            module.save()
            self.log_success(f"Created new module: {module}")

            # Update device description
            device.description = 'THIS WILL BREAK MODULE BAYS'
            device.full_clean()
            device.save()

        except Exception as err:
            self.log_failure(f"Failed: {err}")

@wz4 commented on GitHub (Jan 7, 2024): Here is a script to reproduce the problem. Make sure to update the module_bay variable as needed. ``` from dcim.choices import DeviceStatusChoices from dcim.models import Device, DeviceRole, DeviceType, Module, ModuleBay, ModuleType, Site from extras.scripts import * class CreateSwitch(Script): class Meta: name = "Create Device" description = "Create a device and associated interfaces" scheduling_enabled = False device_name = StringVar( label="Device Name", required=True, ) device_type = ObjectVar( label='Device Type', model=DeviceType ) module_type = ObjectVar( label="Module Type", model=ModuleType ) status = ChoiceVar( label="Status", choices=DeviceStatusChoices ) role = ObjectVar( label='Device Role', model=DeviceRole, ) site = ObjectVar( label='Site', model=Site, ) def run(self, data, commit): module_bay = "slot-1" try: # Create Device device = Device( name=data['device_name'], device_type=data['device_type'], role=data["role"], site=data["site"], ) device.full_clean() device.save() self.log_success(f"Created new device: {device}") # Create Module module = Module( device=device, module_bay=ModuleBay.objects.get(device=device, name=module_bay), module_type=data['module_type'] ) module.full_clean() module.save() self.log_success(f"Created new module: {module}") # Update device description device.description = 'THIS WILL BREAK MODULE BAYS' device.full_clean() device.save() except Exception as err: self.log_failure(f"Failed: {err}") ```
Author
Owner

@wz4 commented on GitHub (Jan 7, 2024):

I have found a workaround to only save the fields that have been updated.

device.description = ip
device.full_clean()
device.save(update_fields=["description"])
@wz4 commented on GitHub (Jan 7, 2024): I have found a workaround to only save the fields that have been updated. ``` device.description = ip device.full_clean() device.save(update_fields=["description"]) ```
Author
Owner

@josh9730 commented on GitHub (Jan 23, 2024):

@wz4 This was exactly the problem. I needed to update an Object custom field after creation, so I ended up just querying for the Device rather than continuing to reference the newly created object, which solved the issue. Thanks for the help!

@josh9730 commented on GitHub (Jan 23, 2024): @wz4 This was exactly the problem. I needed to update an Object custom field after creation, so I ended up just querying for the Device rather than continuing to reference the newly created object, which solved the issue. Thanks for the help!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8976