Front and/or rear ports missing from device components menu when added via script #8697

Closed
opened 2025-12-29 20:40:03 +01:00 by adam · 2 comments
Owner

Originally created by @craized on GitHub (Sep 29, 2023).

NetBox version

v3.6.3

Python version

3.11

Steps to Reproduce

  1. Run a script that calls the following, where is an existing device that does not have any rear ports.
 RearPort.objects.bulk_create([
    RearPort(
        name="MONITOR",
        device=<Device>
        type="sc-upc",
        positions=1,
    ),
    RearPort(
        name="OUTPUT",
        device=<Device>
        type="sc-upc",
        positions=1,
    ),
])
  1. Navigate directly to https://netbox-url/dcim/devices/<device-id>/rear-ports/
  2. Via the GUI, add a Rear Port component
  3. Via the GUI, delete the newly created Rear Port

Expected Behavior

After step 1, the GUI shows a 'Rear Ports' tab for the device.

Observed Behavior

The GUI does not show a 'Rear Ports' tab for the device after addition via script
Navigating directly to the rear-ports URL shows the rear port(s)
After adding a rear port via the GUI, the 'Rear Ports' tab exists
After removing the port created via GUI, the 'Rear Ports' tab disappears (even though there is at least one remaining port)

rear-port-model-safe

Originally created by @craized on GitHub (Sep 29, 2023). ### NetBox version v3.6.3 ### Python version 3.11 ### Steps to Reproduce 1. Run a script that calls the following, where <Device> is an existing device that does not have any rear ports. ``` RearPort.objects.bulk_create([ RearPort( name="MONITOR", device=<Device> type="sc-upc", positions=1, ), RearPort( name="OUTPUT", device=<Device> type="sc-upc", positions=1, ), ]) ``` 2. Navigate directly to `https://netbox-url/dcim/devices/<device-id>/rear-ports/` 3. Via the GUI, add a Rear Port component 4. Via the GUI, delete the newly created Rear Port ### Expected Behavior After step 1, the GUI shows a 'Rear Ports' tab for the device. ### Observed Behavior The GUI does not show a 'Rear Ports' tab for the device after addition via script Navigating directly to the rear-ports URL shows the rear port(s) After adding a rear port via the GUI, the 'Rear Ports' tab exists After removing the port created via GUI, the 'Rear Ports' tab disappears (even though there is at least one remaining port) ![rear-port-model-safe](https://github.com/netbox-community/netbox/assets/499818/40cfd58b-9a9e-4973-8a29-69b7cb5c7d3d)
adam closed this issue 2025-12-29 20:40:03 +01:00
Author
Owner

@arthanson commented on GitHub (Oct 2, 2023):

The new cache counts use signals and bulk_create bypasses Django signal handlers, if you run the management command calculate_cached_counts afterwards it should reset the counters. See the warnings at: https://docs.netbox.dev/en/stable/administration/netbox-shell/#creating-and-updating-objects

Monosnap NetBox Shell - NetBox Documentation 2023-10-02 07-50-21

@arthanson commented on GitHub (Oct 2, 2023): The new cache counts use signals and bulk_create bypasses Django signal handlers, if you run the management command calculate_cached_counts afterwards it should reset the counters. See the warnings at: https://docs.netbox.dev/en/stable/administration/netbox-shell/#creating-and-updating-objects ![Monosnap NetBox Shell - NetBox Documentation 2023-10-02 07-50-21](https://github.com/netbox-community/netbox/assets/99642/7438afb6-65af-423f-89dd-ea99bde0211d)
Author
Owner

@craized commented on GitHub (Oct 2, 2023):

Confirmed that rebuilding caches resolved the missing items. I'll switch to just looping through to call object.save() and hopefully the performance is comparable.

Thank you for pointing me in the right direction

@craized commented on GitHub (Oct 2, 2023): Confirmed that rebuilding caches resolved the missing items. I'll switch to just looping through to call object.save() and hopefully the performance is comparable. Thank you for pointing me in the right direction
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8697