Skip to content

Commit 680782b

Browse files
authored
Merge pull request #969 from pulp/patchback/backports/3.19/30e5999ab986e1c7a2e6221cd5881afe54cb3fb3/pr-962
[PR #962/30e5999a backport][3.19] Fix publish failure when handling bad dist name metadata
2 parents 911d5d1 + 52a3964 commit 680782b

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

CHANGES/907.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed publication error when package's dists contain differing versions of its name.

pulp_python/app/tasks/publish.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ def write_simple_api(publication):
5959
python_models.PythonPackageContent.objects.filter(
6060
pk__in=publication.repository_version.content, _pulp_domain=domain
6161
)
62-
.order_by("name")
62+
.order_by("name__normalize")
6363
.values_list("name", flat=True)
64-
.distinct()
64+
.distinct("name__normalize")
6565
)
6666

6767
# write the root index, which lists all of the projects for which there is a package available
@@ -80,22 +80,22 @@ def write_simple_api(publication):
8080
packages = python_models.PythonPackageContent.objects.filter(
8181
pk__in=publication.repository_version.content, _pulp_domain=domain
8282
)
83-
releases = packages.order_by("name").values("name", "filename", "sha256")
83+
releases = packages.order_by("name__normalize").values("name", "filename", "sha256")
8484

8585
ind = 0
86-
current_name = project_names[ind]
86+
current_name = canonicalize_name(project_names[ind])
8787
package_releases = []
8888
for release in releases.iterator():
89-
if release["name"] != current_name:
89+
if canonicalize_name(release["name"]) != current_name:
9090
write_project_page(
91-
name=canonicalize_name(current_name),
91+
name=current_name,
9292
simple_dir=simple_dir,
9393
package_releases=package_releases,
9494
publication=publication,
9595
)
9696
package_releases = []
9797
ind += 1
98-
current_name = project_names[ind]
98+
current_name = canonicalize_name(project_names[ind])
9999
relative_path = release["filename"]
100100
path = f"../../{relative_path}"
101101
checksum = release["sha256"]

pulp_python/pytest_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def _gen_python_content(relative_path=PYTHON_EGG_FILENAME, url=None, **body):
178178

179179
task = python_bindings.ContentPackagesApi.create(**body).task
180180
response = monitor_task(task)
181-
return python_bindings.ContentPackagesApi.read(response.created_resources[0])
181+
return python_bindings.ContentPackagesApi.read(response.created_resources[-1])
182182

183183
yield _gen_python_content
184184

pulp_python/tests/functional/api/test_crud_publications.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
import random
3+
from pypi_simple import PyPISimple
34
from urllib.parse import urljoin
45

56
from pulp_python.tests.functional.constants import (
@@ -109,3 +110,29 @@ def test_new_content_is_published(python_publication_workflow, python_distributi
109110
url = urljoin(distro.base_url, "simple/")
110111
proper, msgs = ensure_simple(url, {"shelf-reader": releases})
111112
assert proper is True, msgs
113+
114+
115+
@pytest.mark.parallel
116+
def test_non_matching_canonicalized_name(
117+
python_repo, python_content_factory, python_publication_factory, python_distribution_factory
118+
):
119+
"""Ensures a package with dists that have non-matching canonicalized names is published."""
120+
packages = []
121+
filenames = ["msg_parser-1.0.0-py2.py3-none-any.whl", "msg_parser-1.0.0.tar.gz"]
122+
with PyPISimple() as client:
123+
page = client.get_project_page("msg-parser")
124+
for pkg in page.packages:
125+
if pkg.filename in filenames:
126+
c = python_content_factory(pkg.filename, url=pkg.url, repository=python_repo)
127+
if c.filename.endswith(".tar.gz"):
128+
# The metadata name in the SDist is not the same as the Wheel's name
129+
assert c.name == "msg_parser"
130+
else:
131+
assert c.name == "msg-parser"
132+
packages.append(c)
133+
pub = python_publication_factory(repository=python_repo)
134+
distro = python_distribution_factory(publication=pub)
135+
136+
url = urljoin(distro.base_url, "simple/")
137+
proper, msgs = ensure_simple(url, {"msg-parser": filenames})
138+
assert proper is True, msgs

0 commit comments

Comments
 (0)