Skip to content

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

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

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>

This branch has not been deployed

No deployments
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

1 participant