module_bay_count=0 for device created through custom script/nbshell #11145

Closed
opened 2025-12-29 21:40:56 +01:00 by adam · 1 comment
Owner

Originally created by @Tina8S on GitHub (May 8, 2025).

Deployment Type

NetBox Cloud

NetBox Version

v4.2.3

Python Version

3.10

Steps to Reproduce

When creating a device based on a device template with module bays the device shows up as having module_bay_count=0 within the script (At this point the GUI shows module bay tab, though). After saving the device (device.save()) within the script (i.e. after adding primary ipv4 address) the module_bay_count is saved as "0" and even the GUI does no longer show the tab for the module bays. A reverse search for module bays belonging to the device still lists the module bays, though.

Code to reproduce via nbshell:

>>> my_dev_type
<DeviceType: C9410R>
>>> my_dev_type.module_bay_template_count
10
>>> my_test_device = Device.objects.create(name="testdevice", device_type=my_dev_type, role=my_role, site=my_site, serial="wersdf213", status=my_status, comments="Test Test Test")
>>> my_test_device.module_bay_count
0
>>> ModuleBay.objects.filter(device=my_test_device)
<TreeQuerySet [<ModuleBay: Slot 1>, <ModuleBay: Slot 2>, <ModuleBay: Slot 3>, <ModuleBay: Slot 4>, <ModuleBay: Slot 5>, <ModuleBay: Slot 6>, <ModuleBay: Slot 7>, <ModuleBay: Slot 8>, <ModuleBay: Slot 9>, <ModuleBay: Slot 10>]>

Expected Behavior

The module_bay_count should be set to the number of module bays that belong to the device

Observed Behavior

module_bay_count is set to 0 instead and (after saving device within script) no tab for module bays shows up in GUI

Originally created by @Tina8S on GitHub (May 8, 2025). ### Deployment Type NetBox Cloud ### NetBox Version v4.2.3 ### Python Version 3.10 ### Steps to Reproduce When creating a device based on a device template with module bays the device shows up as having module_bay_count=0 within the script (At this point the GUI shows module bay tab, though). After saving the device (device.save()) within the script (i.e. after adding primary ipv4 address) the module_bay_count is saved as "0" and even the GUI does no longer show the tab for the module bays. A reverse search for module bays belonging to the device still lists the module bays, though. Code to reproduce via nbshell: ``` >>> my_dev_type <DeviceType: C9410R> >>> my_dev_type.module_bay_template_count 10 >>> my_test_device = Device.objects.create(name="testdevice", device_type=my_dev_type, role=my_role, site=my_site, serial="wersdf213", status=my_status, comments="Test Test Test") >>> my_test_device.module_bay_count 0 >>> ModuleBay.objects.filter(device=my_test_device) <TreeQuerySet [<ModuleBay: Slot 1>, <ModuleBay: Slot 2>, <ModuleBay: Slot 3>, <ModuleBay: Slot 4>, <ModuleBay: Slot 5>, <ModuleBay: Slot 6>, <ModuleBay: Slot 7>, <ModuleBay: Slot 8>, <ModuleBay: Slot 9>, <ModuleBay: Slot 10>]> ``` ### Expected Behavior The module_bay_count should be set to the number of module bays that belong to the device ### Observed Behavior module_bay_count is set to 0 instead and (after saving device within script) no tab for module bays shows up in GUI
adam added the netbox label 2025-12-29 21:40:56 +01:00
adam closed this issue 2025-12-29 21:40:56 +01:00
Author
Owner

@arthanson commented on GitHub (May 8, 2025):

@Tina8S I'm converting this to a discussion, it sounds like you are having a coding issue with the script and it would get more feedback as a discussion.

@arthanson commented on GitHub (May 8, 2025): @Tina8S I'm converting this to a discussion, it sounds like you are having a coding issue with the script and it would get more feedback as a discussion.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11145