[PR #20704] [MERGED] Fixes #20697: Ensure unique signal handlers for counter models #16016

Closed
opened 2025-12-30 00:25:20 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20704
Author: @pheus
Created: 10/28/2025
Status: Merged
Merged: 10/31/2025
Merged by: @jeremystretch

Base: mainHead: 20697-ensure-unique-signal-handlers-for-counter-models


📝 Commits (1)

  • 8dc0c02 fix(utilities): Ensure unique signal handlers for counter models

📊 Changes

1 file changed (+20 additions, -10 deletions)

View changed files

📝 netbox/utilities/counters.py (+20 -10)

📄 Description

Fixes: #20697

Summary
Prevent double counting in CounterCacheField by ensuring signal receivers are connected once per sender.

Implementation

  • Update utilities.counters.connect_counters() to use per‑sender dispatch_uid for post_save, pre_delete, and post_delete.
  • Guard against reconnecting by tracking models already processed during registration.
  • Leave a single receiver to update all registered counters for the same sender (e.g., device_count and member_count).

Impact

  • Fixes +2/−2 updates when multiple counters share the same child model (e.g., Device).
  • No database changes; backward‑compatible internal wiring change.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/20704 **Author:** [@pheus](https://github.com/pheus) **Created:** 10/28/2025 **Status:** ✅ Merged **Merged:** 10/31/2025 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `main` ← **Head:** `20697-ensure-unique-signal-handlers-for-counter-models` --- ### 📝 Commits (1) - [`8dc0c02`](https://github.com/netbox-community/netbox/commit/8dc0c02bee970a8028c9d572db8816cf664aa70b) fix(utilities): Ensure unique signal handlers for counter models ### 📊 Changes **1 file changed** (+20 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `netbox/utilities/counters.py` (+20 -10) </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be approved and assigned prior to opening a pull request. This helps avoid waste time and effort on a proposed change that we might not be able to accept. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ISSUE WHICH HAS BEEN ASSIGNED TO YOU, IT WILL BE CLOSED AUTOMATICALLY. Please specify your assigned issue number on the line below. --> ### Fixes: #20697 **Summary** Prevent double counting in `CounterCacheField` by ensuring signal receivers are connected **once per sender**. **Implementation** - Update `utilities.counters.connect_counters()` to use per‑sender `dispatch_uid` for `post_save`, `pre_delete`, and `post_delete`. - Guard against reconnecting by tracking models already processed during registration. - Leave a single receiver to update all registered counters for the same sender (e.g., `device_count` and `member_count`). **Impact** - Fixes `+2/−2` updates when multiple counters share the same child model (e.g., `Device`). - No database changes; backward‑compatible internal wiring change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:25:20 +01:00
adam closed this issue 2025-12-30 00:25:20 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#16016