[BUG] get_dependencies in nuget.py crashes with KeyError: '@targetFramework' on dependency groups without targetFramework
Les mainteneurs répondent en général sous 1 jour
@patelshivani2283-lab y travaille déjà.
Depuis le 17/11/2026.
- #5494 par @patelshivani2283-lab — ouverte
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 35/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
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+
- Langage dominant
- Python
- Étoiles
- 2.7k
- Forks
- 871
- Merge moyen
- 1 j 10 h
- PR mergées (30 j)
- 3
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de aboutcode-org/scancode-toolkit
-
yarn.lock v1 with a scoped alias of an unscoped package yields no packages and no errorPeut-être pris @Shubham-dev-stack l’a pris il y a 7 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
aboutcode-org/scancode-toolkit#5466 ·
Les mainteneurs répondent en général sous 1 jour
-
package-lock.json dependencies report file_references as a list inside a listPeut-être pris @Anbarasu2410 l’a pris il y a 10 jours. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
aboutcode-org/scancode-toolkit#5449 · 4 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
scancode aborts when encountering a broken RPM archivePeut-être pris @Ashutosh-Panda2004 l’a pris il y a 14 jours. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
aboutcode-org/scancode-toolkit#5407 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Four silent bugs: IsRequiredPhrase.license_expression returns None, find_in_path ignores later PATH changes, duplicate dict keys override license mappingsPeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouvertebug
Difficulté 2/5 Une demi-journée Accessibilité débutants 65/100
aboutcode-org/scancode-toolkit#5405 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
parse_maintainer_name_email returns empty name and wrong email when string has "@" but no angle bracketsPeut-être pris @RohitSutar1823 l’a pris il y a 15 jours. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
aboutcode-org/scancode-toolkit#5402 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de aboutcode-org/scancode-toolkit
Issues similaires
-
Internal ErrorOuvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
frappe/frappe_docker#2071 ·
Les mainteneurs répondent en général sous 1 jour
-
bug python
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
traceloop/openllmetry#4717 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Ouvertecomp/desktop P2 type/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
NousResearch/hermes-agent#157702 ·
Les mainteneurs répondent en général sous 1 jour
-
scibench_physics / scibench_chemistry: a correct answer scores 0 when the unit has a power of tenPeut-être pris @BahaaMattar l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
EvolvingLMMs-Lab/lmms-eval#1699 ·
Les mainteneurs répondent en général sous 1 jour