PypiVersionAPI.get_latest_date() crashes when a PyPI release entry is missing upload_time_iso_8601

Đang mở
#854 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@RuchitAgrawal đang làm issue này rồi.

Từ ngày 27/3/2026.

  • #921 của @Anurag-S1ngh — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
58/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Trong packagedb/package_managers.py, hãy kiểm tra PypiVersionAPI.get_latest_date() và cách nó xử lý từng mục tải xuống. Sử dụng các ví dụ được cung cấp để kiểm tra các mục có và không có upload_time_iso_8601, sau đó xác minh rằng các dấu thời gian hợp lệ vẫn được so sánh. Được xem là hoàn tất khi các dấu thời gian bị thiếu hoặc không thể sử dụng bị bỏ qua, ngày hợp lệ mới nhất được trả về và None được trả về khi không tồn tại dấu thời gian nào có thể sử dụng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

While reviewing packagedb/package_managers.py, I noticed a bug in PypiVersionAPI.get_latest_date().

The function currently assumes that every download entry in a PyPI release contains upload_time_iso_8601. If one of the entries is missing that field, current_date is never assigned, but it is still used later in the loop. That can raise an UnboundLocalError instead of simply skipping the invalid entry.

Current code:

latest_date = None
for download in downloads:
upload_time = download.get("upload_time_iso_8601")
if upload_time:
current_date = dateparser.parse(upload_time)
if not latest_date:
latest_date = current_date
else:
if current_date > latest_date:
latest_date = current_date
return latest_date
A minimal example that can trigger this is:

downloads = [
{},
{"upload_time_iso_8601": "2010-12-23T05:14:23.509436Z"},
]
In this case, the function should ignore the first item and return the parsed date from the second one, but it can fail on the first item because current_date is undefined.

Expected behavior:

skip entries that do not have upload_time_iso_8601
continue processing the remaining valid entries
return the latest valid date
return None if none of the entries contain a usable timestamp
A simple fix would be to initialize current_date = None inside the loop and continue when upload_time_iso_8601 is missing.

Reference:
PyPI JSON API documentation

Ngôn ngữ chính
HTML
Star
70
Fork
74
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
7

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của aboutcode-org/purldb

Tất cả issue của aboutcode-org/purldb

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.