Repository navigation
Fix KeyError in NuGet .nuspec parsing for groups without targetFramework - #5494
Open
patelshivani2283-lab wants to merge 1 commit into
Conversation
In NuGet .nuspec manifests, Microsoft's specification allows dependency groups to omit the targetFramework attribute to specify a fallback group. Previously, get_dependencies accessed group['@TARGETframework'] directly, causing a KeyError when encountering fallback groups. Additionally: - Extracted license text from the '#text' field when the nuspec <license> element contains XML attributes (e.g., type='expression'). - Supported 'Project' dependency types in packages.lock.json as direct dependencies. Signed-off-by: Shivani Patel <patelshivani2283@gmail.com>
kmlyz
reviewed
Nov 17, 2026
kmlyz
left a comment
There was a problem hiding this comment.
Thanks for the fix, @patelshivani2283-lab. Using group.get('@targetFramework') avoids the KeyError on fallback groups, and all 13 tests in tests/packagedcode/test_nuget.py pass. One note on src/packagedcode/nuget.py: when <license> has type="file", license_val.get('#text') extracts a filename such as LICENSE.txt as extracted_license_statement. Consider checking license_val.get('@type') == 'expression' or adding a type="file" test case.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5493
Tasks
Summary of Changes
src/packagedcode/nuget.py, usedgroup.get('@targetFramework')instead of direct key lookupgroup['@targetFramework'], preventingKeyErrorwhen parsing.nuspecfiles containing fallback<group>tags withouttargetFrameworkattribute.#textfield when<license>has XML attributes (such astype="expression")."type": "Project"inpackages.lock.jsonas direct dependencies (is_direct = True).tests/packagedcode/test_nuget.py:test_parse_nuspec_with_fallback_group_without_target_frameworktest_parse_nuspec_with_expression_licensetest_parse_packages_lock_with_project_dependencyCHANGELOG.rstandAUTHORS.rst.Signed-off-by: patelshivani2283-lab patelshivani2283@gmail.com