Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Duplicate keys in alpine DECLARED_TO_SPDX silently discard two license mappings

Đang mở Phù hợp với người mới
#5,312 0 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 3 ngày

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

Từ ngày 11/9/2026.

  • #5313 của @Daksha1611 — đang mở

Đánh giá

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

Hướng nghiên cứu

Mở src/packagedcode/alpine.py và kiểm tra DECLARED_TO_SPDX cùng với comprehension DECLARED_TO_SPDX_SUBS được dẫn xuất và hiển thị trong issue. Xác minh các key trùng lặp 'as-is' và 'custom:tu-berlin-2.0' tại các dòng được nêu, sau đó điều chỉnh để mỗi key chỉ xuất hiện một lần mà không tạo thêm sự mơ hồ. Chạy kiểm tra AST về key trùng lặp được cung cấp (hoặc một script tương đương) trước và sau khi thay đổi để xác nhận rằng các key trùng lặp đã biến mất; hoàn tất khi cảnh báo key trùng lặp không còn và hành vi của mapping được căn chỉnh rõ ràng theo các giá trị dự kiến.

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

Mô tả

Description

DECLARED_TO_SPDX in src/packagedcode/alpine.py has two duplicate keys. A dict literal keeps only the last value for a repeated key, so the earlier entry of each pair is dead at import time.

'as-is':

  • line 1619: 'as-is': 'licenseref-scancode-free-unknown',
  • line 1701: 'as-is': 'licenseref-scancode-unknown-license-reference',

'custom:tu-berlin-2.0':

  • line 1690: 'custom:tu-berlin-2.0': 'licenseref-scancode-unknown-license-reference',
  • line 1715: 'custom:tu-berlin-2.0': 'tu-berlin-2.0',

Each of the four entries carries its own comment, so the two pairs look like they were added independently without noticing the collision.

This mapping is turned straight into the substitution table applied to every Alpine package license expression:

DECLARED_TO_SPDX_SUBS = {
    licensing.parse(src, simple=True): licensing.parse(tgt, simple=True)
    for src, tgt in DECLARED_TO_SPDX.items()
}

So which value wins is decided by position in the file rather than by intent. For 'as-is' the surviving value is the less specific licenseref-scancode-unknown-license-reference, and the licenseref-scancode-free-unknown mapping never applies.

How To Reproduce
import ast, collections

src = open('src/packagedcode/alpine.py').read()
for node in ast.walk(ast.parse(src)):
    if isinstance(node, ast.Dict):
        counts = collections.Counter(
            k.value for k in node.keys
            if isinstance(k, ast.Constant) and isinstance(k.value, str)
        )
        for key, n in counts.items():
            if n > 1:
                print(f'line {node.lineno}: duplicate key {key!r} x{n}')
line 1568: duplicate key 'as-is' x2
line 1568: duplicate key 'custom:tu-berlin-2.0' x2
Suggested fix

Drop the dead lines so each key appears once. Which of the two values is actually wanted for each key needs a maintainer decision, since right now it is settled by line order — I have opened a PR that removes the unreachable entries and keeps the currently-winning values, so behaviour does not change.

System configuration
  • What OS are you running on? Linux (x86_64)
  • What version of scancode-toolkit was used? 33.0.0rc1, develop at 5ebebf2
  • What installation method was used to install/run scancode? source checkout
  • Python version: 3.x
Ngôn ngữ chính
Python
Star
2.7k
Fork
831
Merge trung bình
3 ngày 4 giờ
Pull request đã merge (30 ngày)
7

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

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/scancode-toolkit

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

Issue tương tự

Thêm issue về Python

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.