Fixes #21498: Fix Exception when changing a Cable Termination with an Interface Event Rule #27

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

Originally created by @pheus on 4/1/2026

Fixes: #21498

This PR fixes a regression in deferred event serialization during cable edits.

When a cable termination is changed, CablePath rows can be deleted and recreated while endpoint instances are still in memory. If an event rule is active, the deferred serialization introduced in v4.5.2 can then hit a stale _path reference and raise CablePath.DoesNotExist.

The DCIM-side fix makes PathEndpoint.path recover from a stale _path reference with a narrow refresh of that field, and routes the remaining internal callers through path instead of accessing _path directly. This prevents the crash and keeps the fix scoped to the denormalized relation involved in path rebuilds.

This PR also includes the EventContext changes intentionally. While the PathEndpoint fix prevents the exception, it does not by itself address stale event payloads when the same object is enqueued multiple times within one request. EventContext now tracks the latest serialization source for coalesced duplicate enqueues, so deferred serialization uses the most recent queued instance while keeping the public object entry unchanged. Delete events are still serialized eagerly before the row becomes unavailable.

Finally, process_event_rules() now avoids mutating event_rule.action_data in place when merging event payload data.

Together, these changes fix the traceback from #21498, preserve the deferred-serialization optimization, and ensure event consumers receive the final queued state for coalesced updates.

*Originally created by @pheus on 4/1/2026* ### Fixes: #21498 This PR fixes a regression in deferred event serialization during cable edits. When a cable termination is changed, `CablePath` rows can be deleted and recreated while endpoint instances are still in memory. If an event rule is active, the deferred serialization introduced in v4.5.2 can then hit a stale `_path` reference and raise `CablePath.DoesNotExist`. The DCIM-side fix makes `PathEndpoint.path` recover from a stale `_path` reference with a narrow refresh of that field, and routes the remaining internal callers through `path` instead of accessing `_path` directly. This prevents the crash and keeps the fix scoped to the denormalized relation involved in path rebuilds. This PR also includes the `EventContext` changes intentionally. While the `PathEndpoint` fix prevents the exception, it does not by itself address stale event payloads when the same object is enqueued multiple times within one request. `EventContext` now tracks the latest serialization source for coalesced duplicate enqueues, so deferred serialization uses the most recent queued instance while keeping the public `object` entry unchanged. Delete events are still serialized eagerly before the row becomes unavailable. Finally, `process_event_rules()` now avoids mutating `event_rule.action_data` in place when merging event payload data. Together, these changes fix the traceback from #21498, preserve the deferred-serialization optimization, and ensure event consumers receive the final queued state for coalesced updates.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#27