Console ports and Power Ports created by scripts ( objects.bulk_create(items) ) do not show in Web UI #11639

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

Originally created by @JCrabtree911 on GitHub (Sep 19, 2025).

NetBox Edition

NetBox Community

NetBox Version

v4.4.1

Python Version

3.11

Steps to Reproduce

  1. Create device
  2. "accidentally" remove an interface, or change the device type to one with a different number of interfaces
  3. Run a script which uses objects.bulk_create(items) to create the missing interfaces.

Expected Behavior

Interfaces and ports should show up in the Web UI regardless of how they were created.

Observed Behavior

Those interfaces do not appear in the Web UI (https://mydcim/dcim/devices/) - They appear in the REST API, and when you manually navigate to the relevant path - for example /dcim/devices//console-ports/ or /dcim/devices//power-ports/

These properties, visible in the REST API, are not correctly updated when the corresponding interface / port types are created with objects.bulk_create()

console_port_count
console_server_port_count
power_port_count
power_outlet_count
interface_count
front_port_count
rear_port_count
device_bay_count
module_bay_count
inventory_item_count

Originally created by @JCrabtree911 on GitHub (Sep 19, 2025). ### NetBox Edition NetBox Community ### NetBox Version v4.4.1 ### Python Version 3.11 ### Steps to Reproduce 1. Create device 2. "accidentally" remove an interface, or change the device type to one with a different number of interfaces 3. Run a script which uses objects.bulk_create(items) to create the missing interfaces. ### Expected Behavior Interfaces and ports should show up in the Web UI regardless of how they were created. ### Observed Behavior Those interfaces do not appear in the Web UI (https://mydcim/dcim/devices/<devicenumber>) - They appear in the REST API, and when you manually navigate to the relevant path - for example /dcim/devices/<device number>/console-ports/ or /dcim/devices/<device number>/power-ports/ These properties, visible in the REST API, are not correctly updated when the corresponding interface / port types are created with objects.bulk_create() console_port_count console_server_port_count power_port_count power_outlet_count interface_count front_port_count rear_port_count device_bay_count module_bay_count inventory_item_count
adam added the netbox label 2025-12-29 21:47:56 +01:00
adam closed this issue 2025-12-29 21:47:56 +01:00
Author
Owner

@jnovinger commented on GitHub (Sep 19, 2025):

@JCrabtree911 , 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.

@jnovinger commented on GitHub (Sep 19, 2025): @JCrabtree911 , 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

@JCrabtree911 commented on GitHub (Sep 19, 2025):

Here's at least three other bug reports which document the same erroneous behavior.

https://github.com/netbox-community/netbox/issues/17980
https://github.com/netbox-community/netbox/issues/19637
https://github.com/netbox-community/netbox/issues/13937

This has been reported over several years and has yet to be fixed. I saw one that referred to running calculate_cached_counts which doesn't seem to appear anywhere in the NetBox documentation. Suffice it say, this is a known bug that keeps getting reported because it has not yet been fixed. bulk_create should either be fixed to provide the expected behavior, or be removed completely to stop people from corrupting their data.

@JCrabtree911 commented on GitHub (Sep 19, 2025): Here's at least three other bug reports which document the same erroneous behavior. https://github.com/netbox-community/netbox/issues/17980 https://github.com/netbox-community/netbox/issues/19637 https://github.com/netbox-community/netbox/issues/13937 This has been reported over several years and has yet to be fixed. I saw one that referred to running calculate_cached_counts which doesn't seem to appear anywhere in the NetBox documentation. Suffice it say, this is a known bug that keeps getting reported because it has not yet been fixed. bulk_create should either be fixed to provide the expected behavior, or be removed completely to stop people from corrupting their data.
Author
Owner

@jnovinger commented on GitHub (Sep 19, 2025):

@JCrabtree911 , thanks for linking those other bug reports.

As you have obviously noticed, all of those issues were closed as they did not actually represent any bug in NetBox. The issue with bulk_create() lies in a technical limitation with Django, the web framework that NetBox is built with, but is explicitly not a bug in NetBox. If you would like to work with the Django team to resolve that, you are more than welcome. However, since bulk_create is not something that NetBox provides, we cannot and will not be removing it.

If you would like to continue the discussion about this particular issue, you must provide more details. Otherwise I will quote Jeremy's response from one of the issues you linked:

We are unable to accept bug reports which rely on custom scripting to reproduce, as this does not necessarily indicate a bug in NetBox. If you'd like assistance with developing a custom script to avoid unwanted behavior, please open a discussion instead.

If you can provide details that point to a reproducible bug in NetBox's custom script implementation, then we are more than willing to look in to it. If you are unable or unwilling to provide the required details, this issue will be closed or converted to a discussion for you.

@jnovinger commented on GitHub (Sep 19, 2025): @JCrabtree911 , thanks for linking those other bug reports. As you have obviously noticed, all of those issues were closed as they did not actually represent any bug in NetBox. The issue with `bulk_create()` lies in a [technical limitation with Django](https://docs.djangoproject.com/en/5.2/ref/models/querysets/#:~:text=the%20pre_save%20and%20post_save%20signals%20will%20not%20be%20sent), the web framework that NetBox is built with, but is explicitly not a bug in NetBox. If you would like to work with the Django team to resolve that, you are more than welcome. However, since `bulk_create` is not something that NetBox provides, we cannot and will not be removing it. If you would like to continue the discussion about this particular issue, you must provide more details. Otherwise I will quote Jeremy's response from one of the issues you linked: > We are unable to accept bug reports which rely on custom scripting to reproduce, as this does not necessarily indicate a bug in NetBox. If you'd like assistance with developing a custom script to avoid unwanted behavior, please open a [discussion](https://github.com/netbox-community/netbox/discussions/new?category=help-wanted) instead. If you can provide details that point to a reproducible bug in NetBox's custom script implementation, then we are more than willing to look in to it. If you are unable or unwilling to provide the required details, this issue will be closed or converted to a discussion for you.
Author
Owner

@JCrabtree911 commented on GitHub (Sep 19, 2025):

This is a problem with NetBox.

Image

It was caused by the script distributed by the NetBox-Community project here https://github.com/netbox-community/customizations/blob/master/scripts/add_device_type_components.py (Updated now, it seems) You should either work around it in NetBox (like, automatically recalculate obviously wrong negative counts) or provide some mitigation for the damage it causes. (like a mechanism to force recalculation of all or selected counts on all or selected devices) Additionally, the Customizations -> Scripts section should detect for and warn about bulk_create when the end user uploads scripts.

@JCrabtree911 commented on GitHub (Sep 19, 2025): This is a problem with NetBox. <img width="299" height="63" alt="Image" src="https://github.com/user-attachments/assets/0acc4d97-36e4-494f-891e-6a9a82f55c3b" /> It was caused by the script distributed by the NetBox-Community project here https://github.com/netbox-community/customizations/blob/master/scripts/add_device_type_components.py (Updated now, it seems) You should either work around it in NetBox (like, automatically recalculate obviously wrong negative counts) or provide some mitigation for the damage it causes. (like a mechanism to force recalculation of all or selected counts on all or selected devices) Additionally, the **Customizations -> Scripts** section should detect for and warn about bulk_create when the end user uploads scripts.
Author
Owner

@jnovinger commented on GitHub (Sep 19, 2025):

This is a problem with NetBox.

No, it is not, as has been explained multiple times.

It was caused by the script distributed by the NetBox-Community project here netbox-community/customizations@master/scripts/add_device_type_components.py (Updated now, it seems) You should either work around it in NetBox (like, automatically recalculate obviously wrong negative counts) or provide some mitigation for the damage it causes. (like a mechanism to force recalculation of all or selected counts on all or selected devices)

Since you clearly feel strongly about this, you are welcome to fork NetBox to implement and maintain this change.

Additionally, the Customizations -> Scripts section should detect for and warn about bulk_create when the end user uploads scripts.

I think you're referring to the scripts directory of the netbox-community/customizations repository here, but I could be wrong. If so, then I suggest you follow up with that project to pursue this idea.

I have made it clear that issues resulting from the use of bulk_create() in custom scripts are not NetBox bugs. In order to be as explicit as possible, the use of bulk_create() in custom scripts is not and will not be supported.

You have been asked twice to provide more details to help us understand if there is a bug in the NetBox custom script implementation. Since you have chosen to not do that, I am closing this issue as not planned.

@jnovinger commented on GitHub (Sep 19, 2025): > This is a problem with NetBox. No, it is not, as has been explained multiple times. > It was caused by the script distributed by the NetBox-Community project here [netbox-community/customizations@`master`/scripts/add_device_type_components.py](https://github.com/netbox-community/customizations/blob/master/scripts/add_device_type_components.py?rgh-link-date=2025-09-19T17%3A37%3A23.000Z) (Updated now, it seems) You should either work around it in NetBox (like, automatically recalculate obviously wrong negative counts) or provide some mitigation for the damage it causes. (like a mechanism to force recalculation of all or selected counts on all or selected devices) Since you clearly feel strongly about this, you are welcome to fork NetBox to implement and maintain this change. > Additionally, the **Customizations -> Scripts** section should detect for and warn about bulk_create when the end user uploads scripts. I _think_ you're referring to the `scripts` directory of the [netbox-community/customizations](https://github.com/netbox-community/customizations) repository here, but I could be wrong. If so, then I suggest you follow up with that project to pursue this idea. I have made it clear that issues resulting from the use of `bulk_create()` in custom scripts are not NetBox bugs. In order to be as explicit as possible, the use of `bulk_create()` in custom scripts is not and will not be supported. You have been asked twice to provide more details to help us understand if there is a bug in the NetBox custom script implementation. Since you have chosen to not do that, I am closing this issue as not planned.
Author
Owner

@JCrabtree911 commented on GitHub (Sep 19, 2025):

Regardless of which dev team is responsible for the underlying bug, users will see impossible (negative) port or interface counts, or not see interfaces that actually exist, and they will blame NetBox.

I think you're referring to the scripts directory of the netbox-community/customizations repository here, but I could be wrong. If so, then I suggest you follow up with that project to pursue this idea.

No I'm talking about this built-in part of NetBox /dcim/extras/scripts/ where the user can actually upload scripts into their instance of NetBox. If this is such a serious problem (it is), users should be blocked from uploading scripts that call bulk_create()

Let's try addressing this a different way, the symptom is that any of these counts can, for any reason, become different from the number of actual ports or interfaces to which they correspond.

console_port_count
console_server_port_count
power_port_count
power_outlet_count
interface_count
front_port_count
rear_port_count
device_bay_count
module_bay_count
inventory_item_count

Additionally, in the instance where the *_count is zero for a given device, but there are actually interfaces or ports, those interfaces or ports will not be displayed on the /devices// page for that device.

The problem is that NetBox provides no apparent way to detect this mismatch, and no apparent way to correct these counts short of simply deleting the device (and all its child devices and cables) and recreating it.

@JCrabtree911 commented on GitHub (Sep 19, 2025): Regardless of which dev team is responsible for the underlying bug, users will see impossible (negative) port or interface counts, or not see interfaces that actually exist, and they will blame NetBox. > I think you're referring to the scripts directory of the [netbox-community/customizations](https://github.com/netbox-community/customizations) repository here, but I could be wrong. If so, then I suggest you follow up with that project to pursue this idea. No I'm talking about this built-in part of NetBox /dcim/extras/scripts/ where the user can actually upload scripts into their instance of NetBox. If this is such a serious problem (it is), users should be blocked from uploading scripts that call bulk_create() Let's try addressing this a different way, the symptom is that any of these counts can, for any reason, become different from the number of actual ports or interfaces to which they correspond. console_port_count console_server_port_count power_port_count power_outlet_count interface_count front_port_count rear_port_count device_bay_count module_bay_count inventory_item_count Additionally, in the instance where the *_count is zero for a given device, but there are actually interfaces or ports, those interfaces or ports will not be displayed on the /devices/<device id>/ page for that device. The problem is that NetBox provides no apparent way to detect this mismatch, and no apparent way to correct these counts short of simply deleting the device (and all its child devices and cables) and recreating it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11639