Fix find_publication_for_distribution#78
Conversation
Sorting the publication list so that the most recent are first fixes creation of some distributions in stackhpc-release-train.
There was a problem hiding this comment.
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.
| for pub in sort_publications(pubs): | ||
| if pub["repository"] == repository_href: | ||
| if not version_href or version_href == pub["repository_version"]: | ||
| return pub |
There was a problem hiding this comment.
Issues
- Robustness & Correctness:
pubscontains all publications in Pulp. Some of these publications might belong to other repositories or other plugins, which might have aNoneor differently formattedrepository_version. Passing the entirepubslist tosort_publicationswill attempt to parse every single publication'srepository_version, potentially leading toAttributeError,ValueError, orKeyErrorand crashing the filter. - 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_hrefand 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.
| 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 |
Sorting the publication list so that the most recent are first fixes creation of some distributions in stackhpc-release-train.