[PR #15166] [MERGED] Fixes #14079: Explicitly remove M2M assignments to objects being deleted to ensure change logging #14536

Closed
opened 2025-12-29 23:25:04 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/15166
Author: @jeremystretch
Created: 2/15/2024
Status: Merged
Merged: 2/16/2024
Merged by: @jeremystretch

Base: developHead: 14079-fix-reverse-m2m-change-logging


📝 Commits (1)

  • 832bf61 Fixes #14079: Explicitly remove M2M assignments to objects being deleted to ensure change logging

📊 Changes

1 file changed (+22 additions, -1 deletions)

View changed files

📝 netbox/extras/signals.py (+22 -1)

📄 Description

Fixes: #14079

This extends the handle_deleted_object() signal receiver to inspect objects being deleted for reverse many-to-many relationships. For any that are found, we query the related model for objects associated with the object being deleted, and manually delete the association by calling remove() on the remote M2M field. This triggers an m2m_changed signal for the related object, ensuring that the change is logged.


🔄 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/15166 **Author:** [@jeremystretch](https://github.com/jeremystretch) **Created:** 2/15/2024 **Status:** ✅ Merged **Merged:** 2/16/2024 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `14079-fix-reverse-m2m-change-logging` --- ### 📝 Commits (1) - [`832bf61`](https://github.com/netbox-community/netbox/commit/832bf613217b0a48cb168a0dcb56403e656b09b7) Fixes #14079: Explicitly remove M2M assignments to objects being deleted to ensure change logging ### 📊 Changes **1 file changed** (+22 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `netbox/extras/signals.py` (+22 -1) </details> ### 📄 Description ### Fixes: #14079 This extends the `handle_deleted_object()` signal receiver to inspect objects being deleted for reverse many-to-many relationships. For any that are found, we query the related model for objects associated with the object being deleted, and manually delete the association by calling `remove()` on the remote M2M field. This triggers an `m2m_changed` signal for the related object, ensuring that the change is logged. --- <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-29 23:25:04 +01:00
adam closed this issue 2025-12-29 23:25:04 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14536