Fixes: #18263 - Iterate through a freshly queried set of CableTerminations to find endpoints in update_connected_endpoints #18264
+2
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #18263
During an API PATCH update to a Cable where one or both endpoints is changed, the signal handler
update_connected_endpoints
iterates throughself.terminations.all()
which in the case of an API call has not necessarily been refreshed after the deletion of stale endpoints atnetbox/netbox/dcim/models/cables.py
Lines 224 to 240 in b6265d8
This leads to the
local_cable_terminations
being empty here (because the pks don't match):netbox/netbox/dcim/models/cables.py
Lines 597 to 611 in b6265d8
Cable.from_origin
), which leads toq_filter
being empty and thus the completely unfiltered iteration at L611 potentially taking O(n) time depending on the number of terminations in the DB.This change ensures that the iteration of CableTerminations associated with a Cable after an update is freshly queried from the DB following the deletion of stale endpoints rather than relying on the (potentially stale or cached)
self.terminations
reverse relation, and thus ensuringfrom_origin
is calculated correctly.