[BUG] get_dependencies in nuget.py crashes with KeyError: '@targetFramework' on dependency groups without targetFramework
Maintainers usually reply within 2 days
@patelshivani2283-lab is already working on this.
Since Nov 17, 2026.
- #5494 by @patelshivani2283-lab — open
Assessment
- Difficulty
- 4/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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+
- Dominant language
- Python
- Stars
- 2.7k
- Forks
- 871
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 3
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from aboutcode-org/scancode-toolkit
-
yarn.lock v1 with a scoped alias of an unscoped package yields no packages and no errorPossibly taken @Shubham-dev-stack claimed this 6 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
aboutcode-org/scancode-toolkit#5466 ·
Maintainers usually reply within 2 days
-
package-lock.json dependencies report file_references as a list inside a listPossibly taken @Anbarasu2410 claimed this 9 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
aboutcode-org/scancode-toolkit#5449 · 4 comments ·
Maintainers usually reply within 2 days
-
scancode aborts when encountering a broken RPM archivePossibly taken @Ashutosh-Panda2004 claimed this 14 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
aboutcode-org/scancode-toolkit#5407 · 3 comments ·
Maintainers usually reply within 2 days
-
Four silent bugs: IsRequiredPhrase.license_expression returns None, find_in_path ignores later PATH changes, duplicate dict keys override license mappingsPossibly taken A pull request linked to this issue is open or already merged. Openbug
Difficulty 2/5 Half a day Newbie friendliness 65/100
aboutcode-org/scancode-toolkit#5405 · 1 comment ·
Maintainers usually reply within 2 days
-
parse_maintainer_name_email returns empty name and wrong email when string has "@" but no angle bracketsPossibly taken @RohitSutar1823 claimed this 14 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
aboutcode-org/scancode-toolkit#5402 ·
Maintainers usually reply within 2 days
All issues in aboutcode-org/scancode-toolkit
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mohanraj00/entelos#200 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
sweep
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bketelsen/truenas-mcp#77 ·
Maintainers usually reply within 1 day
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskOpen
Difficulty 1/5 Under an hour Newbie friendliness 86/100
sandbox-quantum/switch#2163 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
openedx/xblock-lti-consumer#765 ·
Maintainers usually reply within 1 day