[BUG] build_dep in pubspec.py crashes with AttributeError on path, git, or unversioned dependencies
Maintainer antworten meist innerhalb von 1 Tag
@Adnan9-63 arbeitet bereits daran.
Seit 17.11.2026.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Read src/packagedcode/pubspec.py, especially build_dep and collect_deps, then reproduce with the pubspec.yaml shown in the issue. Check whether path, git, and unversioned dependencies parse without crashing and retain their dependency data. Done means the scan returns dependencies instead of an empty package list; linked pull request #5492 is already open.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Problem Description
In src/packagedcode/pubspec.py, the build_dep function assumes version is always a string containing a version number.
When a pubspec.yaml contains:
- Path dependencies (e.g.
path: ../local_pkg) - Git dependencies (e.g.
git: https://github.com/...) - Unversioned dependencies (e.g.
collection:where YAML parses the value asNone)
build_dep crashes with an AttributeError because it calls .replace('.', '') directly on version without verifying that it is a string.
During a scan (scancode --package), this unhandled exception causes ScanCode to fail silently on pubspec.yaml, returning 0 packages and missing all dependencies.
Steps to Reproduce
- Create a
pubspec.yamlcontaining a path dependency and an unversioned dependency:
name: my_flutter_app
version: 1.0.0
dependencies:
flutter:
sdk: flutter
my_local_package:
path: ../my_local_package
collection:
- Run a package scan:
scancode --package --json-pp scan.json pubspec.yaml
-
scan.jsonreportspackages: [](dependencies are completely lost). -
Directly calling
DartPubspecYamlHandler.parsereveals the traceback:
Traceback (most recent call last):
File "src/packagedcode/pubspec.py", line 288, in build_package
package_dependencies.extend(dependencies)
File "src/packagedcode/pubspec.py", line 193, in collect_deps
dep = build_dep(...)
File "src/packagedcode/pubspec.py", line 216, in build_dep
if version.replace('.', '').isdigit():
AttributeError: 'dict' object has no attribute 'replace'
(Or AttributeError: 'NoneType' object has no attribute 'replace' if version is None).
Root Cause
In src/packagedcode/pubspec.py, line 216:
def build_dep(name, version, scope, is_runtime=True, is_optional=False):
if isinstance(version, dict) and 'sdk' in version:
version = ', '.join(': '.join([k, str(v)]) for k, v in version.items())
if version.replace('.', '').isdigit():
purl = PackageURL(
type='pubspec',
name=name,
version=version,
)
is_pinned = True
- If
versionisNone,version.replace(...)raisesAttributeError: 'NoneType' object has no attribute 'replace'. - If
versionis adict(such as{'path': '...'}or{'git': '...'}),version.replace(...)raisesAttributeError: 'dict' object has no attribute 'replace'.
Expected Behavior
- Path and git dependencies should not crash the parser; their mapping should be safely preserved in
extra_data. - Unversioned dependencies should result in a valid
DependentPackagewithextracted_requirement=Noneandis_pinned=False.
Proposed Solution
Safely check types and extract version/extra_data in build_dep:
def build_dep(name, version, scope, is_runtime=True, is_optional=False):
extra_data = {}
extracted_requirement = None
is_pinned = False
if isinstance(version, dict):
if 'sdk' in version:
extracted_requirement = ', '.join(': '.join([k, str(v)]) for k, v in version.items())
else:
extra_data = version
if 'version' in version and isinstance(version['version'], str):
extracted_requirement = version['version']
elif isinstance(version, str):
extracted_requirement = version
if extracted_requirement and isinstance(extracted_requirement, str) and extracted_requirement.replace('.', '').isdigit():
purl = PackageURL(
type='pubspec',
name=name,
version=extracted_requirement,
)
is_pinned = True
else:
purl = PackageURL(
type='pubspec',
name=name,
)
dep = models.DependentPackage(
purl=purl.to_string(),
extracted_requirement=extracted_requirement,
scope=scope,
is_runtime=is_runtime,
is_optional=is_optional,
is_pinned=is_pinned,
extra_data=extra_data,
)
return dep
Environment
- ScanCode version: 33.0.0rc1 / develop branch
- OS: All
- Vorherrschende Sprache
- Python
- Sterne
- 2.7k
- Forks
- 871
- Ø Merge
- 1 T. 10 Std.
- Gemergte PRs (30 T.)
- 3
Entwicklungsumgebung
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus aboutcode-org/scancode-toolkit
-
yarn.lock v1 with a scoped alias of an unscoped package yields no packages and no errorEvtl. vergeben @Shubham-dev-stack hat das vor 6 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
aboutcode-org/scancode-toolkit#5466 ·
Maintainer antworten meist innerhalb von 1 Tag
-
package-lock.json dependencies report file_references as a list inside a listEvtl. vergeben @Anbarasu2410 hat das vor 10 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
aboutcode-org/scancode-toolkit#5449 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
scancode aborts when encountering a broken RPM archiveEvtl. vergeben @Ashutosh-Panda2004 hat das vor 14 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
aboutcode-org/scancode-toolkit#5407 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Four silent bugs: IsRequiredPhrase.license_expression returns None, find_in_path ignores later PATH changes, duplicate dict keys override license mappingsEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenbug
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 65/100
aboutcode-org/scancode-toolkit#5405 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
parse_maintainer_name_email returns empty name and wrong email when string has "@" but no angle bracketsEvtl. vergeben @RohitSutar1823 hat das vor 15 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
aboutcode-org/scancode-toolkit#5402 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in aboutcode-org/scancode-toolkit
Ähnliche Issues
-
author-page correction move-papers
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
acl-org/acl-anthology#10978 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
PostgreSQL results table stores labels with single quotes, and a double quote in a label fails the writeEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
HKUDS/CLI-Anything#652 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Project-N-E-K-O/N.E.K.O#3813 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Dao-AILab/flash-attention#3191 ·
Maintainer antworten meist innerhalb von 4 Tagen