Skip to content

Commit 9e2bd40

Browse files
committed
Fix pull-through not saving metadata artifact
fixes: #1087
1 parent 641bf36 commit 9e2bd40

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

CHANGES/1087.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed pull-through PEP 658 metadata not being saved correctly with the package.

pulp_python/app/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from .provenance import Provenance
2626
from .utils import (
2727
artifact_to_python_content_data,
28+
artifact_to_metadata_artifact,
2829
canonicalize_name,
2930
python_content_to_json,
3031
PYPI_LAST_SERIAL,
@@ -215,7 +216,10 @@ def init_from_artifact_and_relative_path(artifact, relative_path):
215216
"""Used when downloading package from pull-through cache."""
216217
path = PurePath(relative_path)
217218
data = artifact_to_python_content_data(path.name, artifact, domain=get_domain())
218-
return PythonPackageContent(**data)
219+
artifacts = {path.name: artifact}
220+
if metadata_artifact := artifact_to_metadata_artifact(path.name, artifact):
221+
artifacts[f"{path.name}.metadata"] = metadata_artifact
222+
return PythonPackageContent(**data), artifacts
219223

220224
def __str__(self):
221225
"""

pulp_python/tests/functional/api/test_full_mirror.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,50 @@ def test_pull_through_metadata(python_remote_factory, python_distribution_factor
238238
r = requests.get(url2)
239239
assert r.status_code == 200
240240
assert sha256(r.content).hexdigest() == package2.metadata_digests["sha256"]
241+
242+
243+
@pytest.mark.parallel
244+
def test_pull_through_metadata_with_repo(
245+
python_repo_factory,
246+
python_remote_factory,
247+
python_distribution_factory,
248+
pulpcore_bindings,
249+
):
250+
"""Tests that metadata is correctly saved when using pull-through with a repository."""
251+
remote = python_remote_factory(url=PYPI_URL, includes=["pip"])
252+
repo = python_repo_factory()
253+
distro = python_distribution_factory(repository=repo.pulp_href, remote=remote.pulp_href)
254+
255+
pip_url = f"{distro.base_url}simple/pip/"
256+
project_page = ProjectPage.from_response(requests.get(pip_url), "pip")
257+
filename = "pip-26.0.1-py3-none-any.whl"
258+
package = next(p for p in project_page.packages if p.filename == filename)
259+
assert package.has_metadata
260+
assert "?redirect=" in package.url
261+
262+
# Retrieve the metadata and assert the content was not saved to the repository
263+
parts = urlsplit(package.url)
264+
url = urlunsplit((parts[0], parts[1], parts[2] + ".metadata", parts[3], parts[4]))
265+
r = requests.get(url)
266+
assert r.status_code == 200
267+
assert sha256(r.content).hexdigest() == package.metadata_digests["sha256"]
268+
project_page = ProjectPage.from_response(requests.get(pip_url), "pip")
269+
package = next(p for p in project_page.packages if p.filename == filename)
270+
assert package.has_metadata
271+
assert "?redirect=" in package.url
272+
273+
# Now retrieve the package and assert the content was saved with metadata
274+
r = requests.get(package.url)
275+
assert r.status_code == 200
276+
pa = pulpcore_bindings.ArtifactsApi.list(sha256=package.digests["sha256"])
277+
assert pa.count == 1
278+
ma = pulpcore_bindings.ArtifactsApi.list(sha256=package.metadata_digests["sha256"])
279+
assert ma.count == 1
280+
281+
# Check the simple page is updated to point to the local repository
282+
project_page = ProjectPage.from_response(requests.get(pip_url), "pip")
283+
package = next(p for p in project_page.packages if p.filename == filename)
284+
assert "?redirect=" not in package.url
285+
r = requests.get(package.metadata_url)
286+
assert r.status_code == 200
287+
assert sha256(r.content).hexdigest() == package.metadata_digests["sha256"]

0 commit comments

Comments
 (0)