- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.9k
Description
NetBox Edition
NetBox Community
NetBox Version
v4.4.4
Python Version
3.10
Steps to Reproduce
- Have two CounterCacheFieldregistrations that both usedcim.Deviceas the child model, for example:- DeviceType.device_count(count devices by- device_type)
- VirtualChassis.member_count(count devices by- virtual_chassis)
 
- 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.