Skip to content

Commit 8a476ac

Browse files
authored
Merge pull request #725 from pulp/patchback/backports/3.12/fc43b4b253dbec5931d6a230296942e4ba52ec3e/pr-717
[PR #717/fc43b4b2 backport][3.12] Fix package name normalization for package pypi json view
2 parents 27252e1 + ec7b1ac commit 8a476ac

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

CHANGES/716.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed package name normalization issue preventing syncing packages with "." or "_" in their names.

pulp_python/app/models.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from pathlib import PurePath
1919
from .utils import (
20+
canonicalize_name,
2021
get_project_metadata_from_artifact,
2122
parse_project_metadata,
2223
python_content_to_json,
@@ -87,6 +88,8 @@ def content_handler(self, path):
8788
).latest("pulp_created")
8889
except ObjectDoesNotExist:
8990
return None
91+
if len(path.parts) == 2:
92+
path = PurePath(f"simple/{canonicalize_name(path.parts[1])}")
9093
rel_path = f"{path}/index.html"
9194
try:
9295
ca = (
@@ -103,8 +106,9 @@ def content_handler(self, path):
103106
return ArtifactResponse(ca.artifact, headers=headers)
104107

105108
if name:
109+
normalized = canonicalize_name(name)
106110
package_content = PythonPackageContent.objects.filter(
107-
pk__in=self.publication.repository_version.content, name__iexact=name
111+
pk__in=self.publication.repository_version.content, name__normalize=normalized
108112
)
109113
# TODO Change this value to the Repo's serial value when implemented
110114
headers = {PYPI_LAST_SERIAL: str(PYPI_SERIAL_CONSTANT)}

pulp_python/app/pypi/views.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ def retrieve(self, request, path, meta):
327327
elif meta_path.match("*/json"):
328328
name = meta_path.parts[0]
329329
if name:
330-
package_content = content.filter(name__iexact=name)
330+
normalized = canonicalize_name(name)
331+
package_content = content.filter(name__normalize=normalized)
331332
# TODO Change this value to the Repo's serial value when implemented
332333
headers = {PYPI_LAST_SERIAL: str(PYPI_SERIAL_CONSTANT)}
333334
if settings.DOMAIN_ENABLED:

pulp_python/tests/functional/api/test_download_content.py

+29
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,32 @@ def test_full_pulp_to_pulp_sync(
8787
repo3 = python_repo_with_sync(remote3)
8888
summary2 = python_content_summary(repository_version=repo3.latest_version_href)
8989
assert summary2.present["python.python"]["count"] == PYTHON_MD_PACKAGE_COUNT
90+
91+
92+
@pytest.mark.parallel
93+
def test_pulp2pulp_sync_with_oddities(
94+
python_repo_with_sync,
95+
python_remote_factory,
96+
python_publication_factory,
97+
python_distribution_factory,
98+
python_content_summary,
99+
):
100+
"""Test that Pulp can handle syncing packages with wierd names."""
101+
remote = python_remote_factory(includes=["oslo.utils"], url="https://pypi.org")
102+
repo = python_repo_with_sync(remote)
103+
distro = python_distribution_factory(repository=repo)
104+
summary = python_content_summary(repository_version=repo.latest_version_href)
105+
# Test pulp 2 pulp full sync w/ live pypi apis
106+
remote2 = python_remote_factory(includes=[], url=distro.base_url)
107+
repo2 = python_repo_with_sync(remote2)
108+
summary2 = python_content_summary(repository_version=repo2.latest_version_href)
109+
assert summary2.present["python.python"]["count"] > 0
110+
assert summary.present["python.python"]["count"] == summary2.present["python.python"]["count"]
111+
# Test w/ publication
112+
pub = python_publication_factory(repository=repo)
113+
distro2 = python_distribution_factory(publication=pub)
114+
remote3 = python_remote_factory(includes=[], url=distro2.base_url)
115+
repo3 = python_repo_with_sync(remote3)
116+
summary3 = python_content_summary(repository_version=repo3.latest_version_href)
117+
assert summary3.present["python.python"]["count"] > 0
118+
assert summary.present["python.python"]["count"] == summary3.present["python.python"]["count"]

0 commit comments

Comments
 (0)