Skip to content

Fix find_publication_for_distribution#78

Open
priteau wants to merge 1 commit into
masterfrom
pub-for-dist
Open

Fix find_publication_for_distribution#78
priteau wants to merge 1 commit into
masterfrom
pub-for-dist

Conversation

@priteau

@priteau priteau commented Jul 2, 2026

Copy link
Copy Markdown
Member

Sorting the publication list so that the most recent are first fixes creation of some distributions in stackhpc-release-train.

Sorting the publication list so that the most recent are first fixes
creation of some distributions in stackhpc-release-train.
@priteau priteau self-assigned this Jul 2, 2026
@priteau priteau requested a review from a team as a code owner July 2, 2026 12:34

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request modifies plugins/filter/filters.py to sort the publications list using sort_publications before iterating to find a match. The reviewer identified that sorting the entire list is inefficient and potentially error-prone if some publications lack a valid repository_version. They recommend filtering the publications by repository_href first before sorting, and provided a code suggestion to address this.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread plugins/filter/filters.py
Comment on lines +60 to 63
for pub in sort_publications(pubs):
if pub["repository"] == repository_href:
if not version_href or version_href == pub["repository_version"]:
return pub

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant