Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/filter/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def find_publication_for_distribution(dist, repos, pubs, dists):
else:
version_href = None

for pub in pubs:
for pub in sort_publications(pubs):
if pub["repository"] == repository_href:
if not version_href or version_href == pub["repository_version"]:
return pub
Comment on lines +60 to 63

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Issues

  1. Robustness & Correctness: pubs contains all publications in Pulp. Some of these publications might belong to other repositories or other plugins, which might have a None or differently formatted repository_version. Passing the entire pubs list to sort_publications will attempt to parse every single publication's repository_version, potentially leading to AttributeError, ValueError, or KeyError and crashing the filter.
  2. Efficiency: Sorting the entire list of all publications in Pulp (O(N log N)) is unnecessary and inefficient when we only need to find a publication for a specific repository. Filtering the list first to only include publications matching repository_href and then sorting the filtered list is much more efficient (O(N) filtering + sorting a tiny subset).

Recommendation

Filter the publications by repository_href and ensure they have a valid repository_version before passing them to sort_publications.

Suggested change
for pub in sort_publications(pubs):
if pub["repository"] == repository_href:
if not version_href or version_href == pub["repository_version"]:
return pub
matching_pubs = [
pub for pub in pubs
if pub.get("repository") == repository_href and pub.get("repository_version")
]
for pub in sort_publications(matching_pubs):
if not version_href or version_href == pub.get("repository_version"):
return pub

Expand Down
Loading