[PR #14091] [MERGED] Closes #12135: Prevent the deletion of interfaces with children #14314

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/14091
Author: @jeremystretch
Created: 10/20/2023
Status: Merged
Merged: 11/1/2023
Merged by: @jeremystretch

Base: featureHead: 12135-protect-child-interfaces


📝 Commits (8)

  • aeea7e0 Closes #12135: Prevent the deletion of interfaces with children
  • bf4b96c Change PROTECT to RESTRICT
  • e39815b Extend handle_protectederror() to also handle RestrictedError
  • cdb9a0d Fix string translation
  • 2d4a5e9 Merge branch 'feature' into 12135-protect-child-interfaces
  • 9397d2a Update migrations
  • 9eb1ce7 Support bulk removal of parent interfaces via UI if all children are included
  • 210b8d2 Add support for the bulk deletion of restricted objects via REST API

📊 Changes

18 files changed (+215 additions, -27 deletions)

View changed files

📝 docs/models/dcim/interface.md (+3 -0)
📝 docs/models/virtualization/vminterface.md (+3 -0)
📝 netbox/dcim/api/views.py (+5 -0)
netbox/dcim/migrations/0183_protect_child_interfaces.py (+19 -0)
📝 netbox/dcim/models/device_components.py (+1 -1)
📝 netbox/dcim/tests/test_api.py (+27 -0)
📝 netbox/dcim/tests/test_views.py (+30 -0)
📝 netbox/dcim/views.py (+3 -2)
📝 netbox/netbox/api/viewsets/__init__.py (+6 -3)
📝 netbox/netbox/api/viewsets/mixins.py (+8 -2)
📝 netbox/netbox/views/generic/bulk_views.py (+10 -9)
📝 netbox/netbox/views/generic/object_views.py (+3 -3)
📝 netbox/utilities/error_handlers.py (+15 -5)
📝 netbox/virtualization/api/views.py (+5 -0)
netbox/virtualization/migrations/0037_protect_child_interfaces.py (+19 -0)
📝 netbox/virtualization/tests/test_api.py (+26 -0)
📝 netbox/virtualization/tests/test_views.py (+29 -0)
📝 netbox/virtualization/views.py (+3 -2)

📄 Description

Fixes: #12135

  • Change on_delete behavior for parent field Interface and VMInterface from SET_NULL to RESTRICT
  • Update UI & API views to cleanly handle RestrictedError exceptions (the same way as ProtectedError)
  • Update BulkDeleteView to perform all deletions within an atomic transaction
  • Add get_bulk_update_queryset() and get_bulk_destroy_queryset() methods to API viewset mixins to allow overriding the default querysets for bulk operations
  • Update the bulk deletion querysets for device & VM interfaces to order objects by parent, to ensure children are deleted before their parents
  • Add tests for deleting parent interface individually as well as both parent and child interfaces, for both devices and VMs

🔄 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/14091 **Author:** [@jeremystretch](https://github.com/jeremystretch) **Created:** 10/20/2023 **Status:** ✅ Merged **Merged:** 11/1/2023 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `feature` ← **Head:** `12135-protect-child-interfaces` --- ### 📝 Commits (8) - [`aeea7e0`](https://github.com/netbox-community/netbox/commit/aeea7e0d437d03b51d39e88e4b169341486efce7) Closes #12135: Prevent the deletion of interfaces with children - [`bf4b96c`](https://github.com/netbox-community/netbox/commit/bf4b96c0f520c19d978a785369f62130d2c1fd1d) Change PROTECT to RESTRICT - [`e39815b`](https://github.com/netbox-community/netbox/commit/e39815b0faf26d827ef5d4b10ee0c0f8361b01f2) Extend handle_protectederror() to also handle RestrictedError - [`cdb9a0d`](https://github.com/netbox-community/netbox/commit/cdb9a0dcacb8a0793924d06f8d7d370c4d842d95) Fix string translation - [`2d4a5e9`](https://github.com/netbox-community/netbox/commit/2d4a5e935c568fe2bd4d625caa40ed166e4ed622) Merge branch 'feature' into 12135-protect-child-interfaces - [`9397d2a`](https://github.com/netbox-community/netbox/commit/9397d2af0b53a0a28e412e9b8ae02c6a5a32da24) Update migrations - [`9eb1ce7`](https://github.com/netbox-community/netbox/commit/9eb1ce7791395f19b6831caef7a8d0de87d8a4ce) Support bulk removal of parent interfaces via UI if all children are included - [`210b8d2`](https://github.com/netbox-community/netbox/commit/210b8d274f794fd7ca6b2efe00a8eb34ff04c068) Add support for the bulk deletion of restricted objects via REST API ### 📊 Changes **18 files changed** (+215 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `docs/models/dcim/interface.md` (+3 -0) 📝 `docs/models/virtualization/vminterface.md` (+3 -0) 📝 `netbox/dcim/api/views.py` (+5 -0) ➕ `netbox/dcim/migrations/0183_protect_child_interfaces.py` (+19 -0) 📝 `netbox/dcim/models/device_components.py` (+1 -1) 📝 `netbox/dcim/tests/test_api.py` (+27 -0) 📝 `netbox/dcim/tests/test_views.py` (+30 -0) 📝 `netbox/dcim/views.py` (+3 -2) 📝 `netbox/netbox/api/viewsets/__init__.py` (+6 -3) 📝 `netbox/netbox/api/viewsets/mixins.py` (+8 -2) 📝 `netbox/netbox/views/generic/bulk_views.py` (+10 -9) 📝 `netbox/netbox/views/generic/object_views.py` (+3 -3) 📝 `netbox/utilities/error_handlers.py` (+15 -5) 📝 `netbox/virtualization/api/views.py` (+5 -0) ➕ `netbox/virtualization/migrations/0037_protect_child_interfaces.py` (+19 -0) 📝 `netbox/virtualization/tests/test_api.py` (+26 -0) 📝 `netbox/virtualization/tests/test_views.py` (+29 -0) 📝 `netbox/virtualization/views.py` (+3 -2) </details> ### 📄 Description ### Fixes: #12135 - Change `on_delete` behavior for `parent` field Interface and VMInterface from `SET_NULL` to `RESTRICT` - Update UI & API views to cleanly handle RestrictedError exceptions (the same way as ProtectedError) - Update BulkDeleteView to perform all deletions within an atomic transaction - Add `get_bulk_update_queryset()` and `get_bulk_destroy_queryset()` methods to API viewset mixins to allow overriding the default querysets for bulk operations - Update the bulk deletion querysets for device & VM interfaces to order objects by parent, to ensure children are deleted before their parents - Add tests for deleting parent interface individually as well as both parent and child interfaces, for both devices and VMs --- <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:23:45 +01:00
adam closed this issue 2025-12-29 23:23:45 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14314