Fix artifact listing to include PyPI proxy cached packages

The list_package_artifacts endpoint was only querying artifacts via the
Upload table. PyPI proxy creates PackageVersion records but not Upload
records, so cached packages would show stats (size, version count) but
no artifacts in the listing.

Now queries artifacts from both Upload and PackageVersion tables using
a union, so PyPI-cached packages display their artifacts correctly.
This commit is contained in:
Mondo Diaz
2026-02-03 16:46:35 -06:00
parent da3fd7a601
commit dc9c217d8a

View File

@@ -4748,14 +4748,20 @@ def list_package_artifacts(
if not package:
raise HTTPException(status_code=404, detail="Package not found")
# Get distinct artifacts uploaded to this package via uploads table
artifact_ids_subquery = (
db.query(func.distinct(Upload.artifact_id))
# Get distinct artifacts for this package from both sources:
# 1. Upload table (traditional uploads)
# 2. PackageVersion table (PyPI proxy cached packages, version-based lookups)
upload_artifact_ids = (
db.query(Upload.artifact_id)
.filter(Upload.package_id == package.id)
.subquery()
)
version_artifact_ids = (
db.query(PackageVersion.artifact_id)
.filter(PackageVersion.package_id == package.id)
)
combined_artifact_ids = upload_artifact_ids.union(version_artifact_ids).subquery()
query = db.query(Artifact).filter(Artifact.id.in_(artifact_ids_subquery))
query = db.query(Artifact).filter(Artifact.id.in_(combined_artifact_ids))
# Apply content_type filter
if content_type: