[BUG] get_dependencies in nuget.py crashes with KeyError: '@targetFramework' on dependency groups without targetFramework
Maintainer thường phản hồi trong vòng 1 ngày
@patelshivani2283-lab đang làm issue này rồi.
Từ ngày 17/11/2026.
- #5494 của @patelshivani2283-lab — đang mở
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start with get_dependencies() in src/packagedcode/nuget.py and inspect the existing NuGet package tests for .nuspec dependency groups and license parsing. The issue also reports that packages.lock.json project references of type Project are rejected; check the related lockfile handling and tests. Reproduce the fallback group crash, then confirm all three reported cases are covered and scans complete without errors.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
In NuGet .nuspec manifests, dependency <group> elements can specify target frameworks. According to Microsoft's NuGet nuspec reference documentation:
"A
<dependencies>element can contain one<group>tag without atargetFrameworkattribute to specify a fallback group that is applied when no specific targetFramework matches the project."
Currently, scancode-toolkit's get_dependencies() in src/packagedcode/nuget.py accesses group['@targetFramework'] directly:
for group in groups:
extra_data = dict(framework=group['@targetFramework'])
deps = group.get('dependency') or []
yield from _get_dep_packs(deps, extra_data)
When scanning any .nuspec that includes a fallback <group> without targetFramework, this raises an unhandled KeyError: '@targetFramework' and aborts the scan.
Additionally:
- When
<license type="expression">...</license>is used in.nuspec,xmltodictparses the element as a dictionary ({'@type': 'expression', '#text': '...'}). Becausenuspec.get('license')was passed directly,extracted_license_statementreceived the dictionary, resulting in a stringified mapping rather than extracting the license expression string. - In
packages.lock.json, project references with"type": "Project"were not recognized, raisingException: Unknown package type: Project.
How To Reproduce
- Create a
test.nuspecwith a fallback group:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>SamplePackage</id>
<version>1.0.0</version>
<dependencies>
<group>
<dependency id="FallbackDep" version="1.0.0" />
</group>
<group targetFramework="net6.0">
<dependency id="Net6Dep" version="2.0.0" />
</group>
</dependencies>
</metadata>
</package>
- Scan the file:
./scancode --package --json - test.nuspec
- Observe traceback:
KeyError: '@targetFramework'
Expected Behavior
- Dependencies in a fallback
<group>withouttargetFrameworkshould be extracted without crashing. extra_data['framework']should be set whentargetFrameworkis present, or omitted when absent.- The
<license>element text should be cleanly extracted even when attributes liketype="expression"are present.
System configuration
- OS: macOS / Linux / Windows
- ScanCode version: 33.0.0rc1 / develop branch
- Python version: 3.10+
- Ngôn ngữ chính
- Python
- Star
- 2.7k
- Fork
- 871
- Merge trung bình
- 1 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aboutcode-org/scancode-toolkit
-
yarn.lock v1 with a scoped alias of an unscoped package yields no packages and no errorCó thể đã có người làm @Shubham-dev-stack đã nhận 6 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
aboutcode-org/scancode-toolkit#5466 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
package-lock.json dependencies report file_references as a list inside a listCó thể đã có người làm @Anbarasu2410 đã nhận 9 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
aboutcode-org/scancode-toolkit#5449 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
scancode aborts when encountering a broken RPM archiveCó thể đã có người làm @Ashutosh-Panda2004 đã nhận 14 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
aboutcode-org/scancode-toolkit#5407 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Four silent bugs: IsRequiredPhrase.license_expression returns None, find_in_path ignores later PATH changes, duplicate dict keys override license mappingsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 65/100
aboutcode-org/scancode-toolkit#5405 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
parse_maintainer_name_email returns empty name and wrong email when string has "@" but no angle bracketsCó thể đã có người làm @RohitSutar1823 đã nhận 15 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
aboutcode-org/scancode-toolkit#5402 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của aboutcode-org/scancode-toolkit
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
mohanraj00/entelos#200 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Dead url in mise.tomlĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
-
sweep
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
bketelsen/truenas-mcp#77 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
sandbox-quantum/switch#2163 ·
Maintainer thường phản hồi trong vòng 1 ngày