Fixes #21618: Preserve cable terminations when bulk-editing cable profile #186

Closed
opened 2026-04-05 16:22:46 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @GeertJohan on 3/9/2026

Fixes: #21618

Summary

  • Cache termination objects in update_terminations() before deleting CableTermination records when force=True
  • Without this fix, the a_terminations/b_terminations properties query the DB after deletion and return empty lists, causing all terminations to be silently lost
  • Removes a leftover debug print() statement from PR #21069

Root Cause

PR #21069 added update_terminations(force=True) to handle profile changes. This method first deletes all existing CableTermination records, then reads self.a_terminations/self.b_terminations to recreate them. When the single-object edit form is used, these properties are populated from form data (_a_terminations/_b_terminations private attrs). But during bulk edit (or any save() without explicitly setting terminations), the properties fall back to self.terminations.all() — which returns empty results because the records were just deleted.

The fix caches the termination objects from get_terminations() into _a_terminations/_b_terminations before the delete step, so they're available for recreation.

Test plan

  • Added test_cable_profile_change_preserves_terminations to CableTestCase
  • Verified test fails without the fix (AssertionError: 0 != 2)
  • Verified test passes with the fix
  • All existing CableTestCase tests pass
  • Cable path tests (test_cablepaths2) unaffected

🤖 Generated with Claude Code

*Originally created by @GeertJohan on 3/9/2026* ### Fixes: #21618 ## Summary - Cache termination objects in `update_terminations()` before deleting `CableTermination` records when `force=True` - Without this fix, the `a_terminations`/`b_terminations` properties query the DB after deletion and return empty lists, causing all terminations to be silently lost - Removes a leftover debug `print()` statement from PR #21069 ## Root Cause PR #21069 added `update_terminations(force=True)` to handle profile changes. This method first deletes all existing `CableTermination` records, then reads `self.a_terminations`/`self.b_terminations` to recreate them. When the single-object edit form is used, these properties are populated from form data (`_a_terminations`/`_b_terminations` private attrs). But during bulk edit (or any `save()` without explicitly setting terminations), the properties fall back to `self.terminations.all()` — which returns empty results because the records were just deleted. The fix caches the termination objects from `get_terminations()` into `_a_terminations`/`_b_terminations` before the delete step, so they're available for recreation. ## Test plan - [x] Added `test_cable_profile_change_preserves_terminations` to `CableTestCase` - [x] Verified test **fails** without the fix (`AssertionError: 0 != 2`) - [x] Verified test **passes** with the fix - [x] All existing `CableTestCase` tests pass - [x] Cable path tests (`test_cablepaths2`) unaffected 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#186