Skip to content

fix(poetry): handle multi-constraint lockfile deps - #1157

Draft
evan-mercer-dev wants to merge 1 commit into
CycloneDX:mainfrom
evan-mercer-dev:fix/poetry-lock-multi-constraint-deps
Draft

evan-mercer-dev wants to merge 1 commit into
CycloneDX:mainfrom
evan-mercer-dev:fix/poetry-lock-multi-constraint-deps

Conversation

@evan-mercer-dev

Copy link
Copy Markdown

Description

When poetry.lock contains a multi-constraint dependency entry (list[dict]) under [package.dependencies] (written by Poetry whenever a locked package has marker-split constraints on the same dependency), PoetryBB._parse_lock() previously wrapped the list as {'version': [...]} instead of normalizing it to a list of dependency spec mappings. As a result, PoetryBB.__add_dep():

  1. Evaluated dep_spec.get('optional') as None even when every constraint in the list had optional = true, including uninstalled optional transitive packages in the SBOM when the corresponding extra was not enabled.
  2. Evaluated dep_spec.get('extras', ()) as (), dropping transitive extras and omitting cdx:python:package:required-extra properties and extra dependencies from the SBOM.

This change extracts PoetryBB._normalize_dep_specs() to normalize str | dict | list dependency declarations into list[T_NameDict] across both _make_bom() and _parse_lock() (aligning lockfile parsing with #842), skips transitive dependencies in __add_dep() when all constraint entries have optional = true, and aggregates extras across all constraint entries into a reusable tuple passed to each matching lock entry.

Unit and CLI regression tests are added in tests/unit/test_poetry.py covering all-optional exclusion when unused, inclusion when the parent extra is enabled, mixed optional/non-optional constraints, and transitive extras propagation across multi-version lock entries.

Resolves or fixes issue: #1151

AI Tool Disclosure

  • My contribution does not include any AI-generated content
  • My contribution includes AI-generated content, as disclosed below:
    • AI Tools: Gemini CLI
    • LLMs and versions: Gemini 2.5 Pro
    • Prompts: Trace how PoetryBB._make_bom (#842) normalizes multi-constraint dependency entries vs PoetryBB._parse_lock / __add_dep for #1151, implement symmetric list[T_NameDict] normalization, and add unit regression tests verifying optional filtering and transitive extras propagation.

Affirmation

Normalize `[package.dependencies]` entries in `poetry.lock` to a list of
dependency spec dicts via `PoetryBB._normalize_dep_specs()`, matching how
`_make_bom()` normalizes multi-constraint declarations in `pyproject.toml`
(CycloneDX#842).

In `__add_dep()`, skip a locked dependency when all of its constraint
entries are marked `optional = true`, and propagate `extras` across all
constraint entries to each matching lock entry.

Fixes CycloneDX#1151

Signed-off-by: Evan Mercer <356857887+evan-mercer-dev@users.noreply.github.com>
@evan-mercer-dev
evan-mercer-dev requested a review from a team as a code owner November 26, 2026 13:12
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 7 complexity · 0 duplication

Metric Results
Complexity ✅ 7 (≤ 20 complexity)
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@jkowalleck

Copy link
Copy Markdown
Member

not accepting a fix unless the report was triaged.
putting this to "draft" until triage of #1151 was done.

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] cyclonedx-py poetry ignores optional and extras on multi-constraint [package.dependencies] entries in poetry.lock

2 participants