Skip to content

Commit b2754bf

Browse files
committed
Fix nondeterministic simple API package ordering
Add stable secondary ordering for project names and package filenames when generating the Python simple API.\n\nAssisted-by: AI (Codex)
1 parent 889037a commit b2754bf

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎pulp_python/app/tasks/publish.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ def write_simple_api(publication):
5656
domain = get_domain()
5757
simple_dir = "simple/"
5858
os.mkdir(simple_dir)
59+
# Secondary ORDER BY makes DISTINCT ON pick a stable display name when
60+
# metadata names differ but canonicalize to the same name_normalized
61+
# (e.g. msg-parser vs msg_parser).
5962
project_names = (
6063
python_models.PythonPackageContent.objects.filter(
6164
pk__in=publication.repository_version.content, _pulp_domain=domain
6265
)
63-
.order_by("name_normalized")
66+
.order_by("name_normalized", "name")
6467
.values_list("name", flat=True)
6568
.distinct("name_normalized")
6669
)
@@ -81,7 +84,7 @@ def write_simple_api(publication):
8184
packages = python_models.PythonPackageContent.objects.filter(
8285
pk__in=publication.repository_version.content, _pulp_domain=domain
8386
)
84-
releases = packages.order_by("name_normalized").values("name", "filename", "sha256")
87+
releases = packages.order_by("name_normalized", "filename").values("name", "filename", "sha256")
8588

8689
ind = 0
8790
current_name = canonicalize_name(project_names[ind])

0 commit comments

Comments
 (0)