Skip to content

Fix AttributeError in build_dep on path, git, and unversioned dependencies (fixes #5491) - #5492

Closed
muskan-creates352 wants to merge 1 commit into
aboutcode-org:developfrom
muskan-creates352:fix-pubspec-build-dep-crash-5491
Closed

muskan-creates352 wants to merge 1 commit into
aboutcode-org:developfrom
muskan-creates352:fix-pubspec-build-dep-crash-5491

Conversation

@muskan-creates352

Copy link
Copy Markdown

Fixes #5491

Problem

In src/packagedcode/pubspec.py, build_dep assumed that version is always a string and called version.replace('.', '').isdigit().
When a pubspec.yaml contained:

  1. Path dependencies (e.g. path: ../local_pkg)
  2. Git dependencies (e.g. git: https://github.com/...)
  3. Unversioned dependencies (e.g. collection: where YAML parses the value as None or "")

build_dep crashed with AttributeError: 'NoneType' object has no attribute 'replace' or AttributeError: 'dict' object has no attribute 'replace', causing ScanCode to silently drop all dependencies during a scan.

Solution

  1. In src/packagedcode/pubspec.py:
    • Updated build_dep to safely handle dict (path, git, hosted) and None/empty string version values.
    • Preserved mapping metadata in extra_data for non-SDK dict dependencies.
    • Guarded pinned version detection with isinstance(extracted_requirement, str).
  2. Added unit tests test_build_dep_non_string_versions and test_parse_pubspec_yaml_path_git_unversioned_dependencies in tests/packagedcode/test_pubspec.py.

Checklist

  • Signed-off-by included in commit message
  • Unit tests added and all 14 pubspec tests pass
  • Tested on Python 3.11

…ncies (fixes aboutcode-org#5491)

Signed-off-by: Muskan Kumari <er.muskan09@gmail.com>

@kmlyz kmlyz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overlaps with open PRs #5487 and #5488, which also update build_dep in src/packagedcode/pubspec.py. In addition, if pubspec.yaml contains an unquoted numeric version (int or float from saneyaml), elif isinstance(version, str): skips it and drops extracted_requirement to None instead of converting via str(version). Also, version.get('version') in a hosted mapping could be non-string if unquoted in YAML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] build_dep in pubspec.py crashes with AttributeError on path, git, or unversioned dependencies

2 participants