Repository navigation
Description
Describe the bug
When poetry.lock contains a multi-constraint dependency entry (list[dict]) under [package.dependencies], cyclonedx-py poetry wraps the list as {'version': [...]} instead of normalizing it as a sequence of dependency specs (unlike root dependencies in pyproject.toml, which were fixed in #840 / #842).
Poetry writes a TOML array of inline tables under [package.dependencies] whenever a locked package has marker-split constraints on the same dependency (for example ray 2.42.1's py-spy optional serve dependency in tests/_data/infiles/poetry/regression-issue702/lock21/poetry.lock). Because dep_spec becomes {'version': [...]}, cyclonedx-py poetry:
- Ignores
optional = true(dep_spec.get('optional')isNone), adding uninstalled optional transitive packages present inpoetry.lockto the SBOM and dependency graph even when the extra is not enabled. - Drops
extras = [...](dep_spec.get('extras', ())is()), omitting transitive extra dependencies andcdx:python:package:required-extraproperties from the SBOM.
To Reproduce
Case 1: Uninstalled optional = true multi-constraint dependency included
Create pyproject.toml where ray is used without extras in main and ray[serve] is only in dev:
[tool.poetry]
name = "demo"
version = "0.1.0"
description = ""
authors = ["Example <[email protected]>"]
[tool.poetry.dependencies]
python = "^3.11"
ray = "2.42.1"
[tool.poetry.group.dev.dependencies]
ray = { version = "2.42.1", extras = ["serve"] }Lock and generate the main-only SBOM:
poetry lock
cyclonedx-py poetry --only main --of JSON .In poetry.lock, Poetry 2.x writes single-table optional = true entries for aiohttp, fastapi, prometheus-client, uvicorn, etc., and a two-entry list for py-spy (python_version < "3.12" and extra == "serve" / python_version >= "3.12" and extra == "serve", both with optional = true). Running cyclonedx-py poetry --only main excludes all single-table serve dependencies, but includes py-spy in components and in ray's dependencies.
Case 2: Transitive extras dropped on a multi-constraint dependency
Create pyproject.toml:
[tool.poetry]
name = "demo"
version = "0.1.0"
description = ""
authors = ["Example <[email protected]>"]
[tool.poetry.dependencies]
python = "^3.11"
app-lib = "^1.0.0"and poetry.lock:
[[package]]
name = "app-lib"
version = "1.0.0"
description = ""
optional = false
python-versions = ">=3.10"
groups = ["main"]
files = []
[package.dependencies]
httpx = [
{version = ">=0.26", extras = ["http2"], markers = "python_version < \"3.12\""},
{version = ">=0.27", extras = ["http2"], markers = "python_version >= \"3.12\""},
]
[[package]]
name = "httpx"
version = "0.27.0"
description = "The next generation HTTP client."
optional = false
python-versions = ">=3.8"
groups = ["main"]
files = []
[package.extras]
http2 = ["h2 (>=4.0)"]
[[package]]
name = "h2"
version = "4.1.0"
description = "HTTP/2 State-Machine based protocol implementation"
optional = false
python-versions = ">=3.8"
groups = ["main"]
files = []
[metadata]
lock-version = "2.1"
python-versions = "^3.11"
content-hash = "0000000000000000000000000000000000000000000000000000000000000000"Run:
cyclonedx-py poetry --of JSON .Expected behavior
- In Case 1,
py-spyhasoptional = trueon every entry in its constraint list andserveis not enabled inmain, sopy-spyshould be excluded from the--only mainSBOM just like single-tableoptional = truedependencies. - In Case 2,
httpx'shttp2extra should be propagated so[email protected](andcdx:python:package:required-extra = "http2"on[email protected]) is included in the SBOM, matching single-table{version = ">=0.27", extras = ["http2"]}entries and root multi-constraint handling in_make_bom.
Screenshots or output-paste
- In Case 1, the JSON BOM from
cyclonedx-py poetry --only main --of JSON .includespy-spy(0.4.0) incomponentsand inray'sdependencies, while excluding all single-tableextra == "serve"optional packages. - In Case 2, the JSON BOM from
cyclonedx-py poetry --of JSON .contains onlyapp-lib(1.0.0) andhttpx(0.27.0) incomponents, omittingh2(4.1.0) andcdx:python:package:required-extraonhttpx(_parse_lockstores thehttpxdependency spec as{'version': [{'version': '>=0.26', 'markers': "python_version < '3.12'", 'extras': ['http2']}, {'version': '>=0.27', 'markers': "python_version >= '3.12'", 'extras': ['http2']}]}).
Environment
- cyclonedx-py version:
9.0.0(PyPIcyclonedx-bom==9.0.0) andmain(087a93338905b6c3b4169cb8c35721b442c23ae4) - Python version:
Python 3.11 - OS: Linux (
x86_64)
Additional context
In cyclonedx_py/_internal/poetry.py (lines 388-391), PoetryBB._parse_lock() builds each _LockEntry.dependencies mapping with:
dependencies={
normalize_packagename(dn): ds if isinstance(ds, dict) else {'version': ds}
for dn, ds in package.get('dependencies', {}).items()
},When ds is a list[dict], isinstance(ds, dict) is False, so ds is wrapped as {'version': ds} instead of normalizing dict | list[dict] | str to list[dict] and checking all(d.get('optional') for d in dep_specs) and chain.from_iterable(d.get('extras', ()) for d in dep_specs) in __add_dep() (lines 337-350), as _make_bom() already does for pyproject.toml dependencies at lines 298-322.
Contribution
- I am willing to provide a fix
- I will wait until somebody else fixes it
Credit: https://ucsbplse.github.io/
Activity
jkowalleck commentedon Nov 26, 2026
sorry, description unclear.
is this about poetry 1or poetry 2?
trackoor commentedon Nov 26, 2026
Sorry, should have said! It's Poetry 2 (lock-version 2.1). The
regression-issue702/lock21fixture in this repo has the same kind of entry, if that's easier to look at.jkowalleck commentedon Nov 27, 2026
poetry2 is not supported, yet.
see #839
Closing as invalid/not planned
jkowalleck commentedon Nov 27, 2026
if there is a bug with Poetry1, feel free to open a dedicated ticket for this