Skip to content

Per‑sender duplicate signal registration causes CounterCacheField double‑counting #20697

@pheus

Description

@pheus

NetBox Edition

NetBox Community

NetBox Version

v4.4.4

Python Version

3.10

Steps to Reproduce

  1. Have two CounterCacheField registrations that both use dcim.Device as the child model, for example:
    • DeviceType.device_count (count devices by device_type)
    • VirtualChassis.member_count (count devices by virtual_chassis)
  2. Create or delete a single Device.

Expected Behavior

Each create/delete updates the relevant counters once (e.g., device_count += 1 on create, device_count -= 1 on delete).

Observed Behavior

Counters update twice (e.g., +2 on create, -2 on delete).

Root Cause

In the counters registry (utilities/counters.py), the dispatch_uid for signal connections is currently formed from the model and field (conceptually {model._meta.label}.{field.name}).
When multiple counters share the same sender (e.g., Device via device_type_id and virtual_chassis_id), this yields different UIDs, so Django connects the same receiver multiple times for that sender. A single post_save emission for Device is then handled twice, doubling the counter updates.

Related Work

This was uncovered while developing FR #19523 (instance/usage filtering), which depends on accurate device_count/module_count values.

Metadata

Metadata

Assignees

Labels

netboxseverity: lowDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions