Skip to content

bug(python): Poetry dependency edges are lost for marker-specific constraints and multiple locked versions #11752

Backlog

Description

@DmitriyLewen

Description

Trivy builds the Poetry dependency graph from the [package.dependencies] sections of poetry.lock (pkg/dependency/parser/python/poetry/parse.go).
The Poetry analyzer then walks the graph from the direct dependencies in pyproject.toml and marks every package it cannot reach as a development dependency.
Development dependencies are hidden by default (--include-dev-deps shows them), so a package whose edge is lost disappears from the results: from vulnerability scanning and from the SBOM.

An edge is lost in two cases.

Reported in #11318.

1. Array of constraints

When a package requires the same dependency with different constraints for different environment markers, Poetry writes an array of inline tables.
For example, pandas 3 → numpy:

[package.dependencies]
numpy = [
    {version = ">=1.26.0", markers = "python_version < \"3.14\""},
    {version = ">=2.3.3", markers = "python_version >= \"3.14\""},
]

The parser only understands a string (numpy = ">=1.26.0") and a single inline table (numpy = {version = ">=1.26.0", markers = "..."}).
For an array it gets an empty constraint, matching fails, and the edge is dropped.
With --debug:

DEBUG	[poetry] Failed to parse poetry dependency	err="failed to match version for numpy: python constraint error (): improper specifier: "

Reproduction

mkdir repro-a && cd repro-a
cat > pyproject.toml <<'EOF'
[project]
name = "repro"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["pandas>=3"]
EOF
cat > poetry.lock <<'EOF'
[[package]]
name = "numpy"
version = "2.5.3"
optional = false
python-versions = ">=3.12"
groups = ["main"]
files = []

[[package]]
name = "pandas"
version = "3.0.6"
optional = false
python-versions = ">=3.11"
groups = ["main"]
files = []

[package.dependencies]
numpy = [
    {version = ">=1.26.0", markers = "python_version < \"3.14\""},
    {version = ">=2.3.3", markers = "python_version >= \"3.14\""},
]

[metadata]
lock-version = "2.1"
python-versions = ">=3.12"
content-hash = "0000000000000000000000000000000000000000000000000000000000000000"
EOF
trivy fs --format cyclonedx . | jq -r '.components[] | select(.type == "library") | "\(.name)@\(.version)"'

Expected: numpy@2.5.3 and pandas@3.0.6.
Actual: only pandas@3.0.6.
With --include-dev-deps numpy shows up, but the graph has no pandas → numpy edge.

2. Several locked versions of the same package

Poetry can lock several versions of one package, each for its own markers.
For example, with requires-python = ">=3.11" the lock file gets numpy 2.4.6 for Python 3.11 and numpy 2.5.3 for Python 3.12 and later.
The parser links a dependency only to the first locked version that satisfies the constraint.
The other versions get no incoming edges, are treated as development dependencies and are hidden.

This is independent of case 1: the same happens with a plain string constraint that both versions satisfy.

The difficulty is that Trivy does not evaluate markers: it does not know which Python version and platform the project will be installed on.
So the lock file alone does not tell which of the locked versions will actually be installed.

Reproduction

mkdir repro-b && cd repro-b
cat > pyproject.toml <<'EOF'
[project]
name = "repro"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = ["pandas>=3"]
EOF
cat > poetry.lock <<'EOF'
[[package]]
name = "numpy"
version = "2.4.6"
optional = false
python-versions = ">=3.11"
groups = ["main"]
markers = "python_version == \"3.11\""
files = []

[[package]]
name = "numpy"
version = "2.5.3"
optional = false
python-versions = ">=3.12"
groups = ["main"]
markers = "python_version >= \"3.12\""
files = []

[[package]]
name = "pandas"
version = "3.0.6"
optional = false
python-versions = ">=3.11"
groups = ["main"]
files = []

[package.dependencies]
numpy = ">=1.26.0"

[metadata]
lock-version = "2.1"
python-versions = ">=3.11"
content-hash = "0000000000000000000000000000000000000000000000000000000000000000"
EOF
trivy fs --format cyclonedx . | jq -r '.components[] | select(.type == "library") | "\(.name)@\(.version)"'

Expected: numpy@2.4.6, numpy@2.5.3 and pandas@3.0.6.
Actual: numpy@2.4.6 and pandas@3.0.6.

Environment

Reproduced with Trivy 0.76.2 and on the current main.

Related

Activity

  1. added
    kind/bug
    on Nov 26, 2026
  2. lxcxjxhx commented on Nov 26, 2026

    @lxcxjxhx
    Contributor

    I am picking up case 1 (array of constraints) from this report; case 2 (several locked versions of one package) needs marker evaluation, which Trivy does not do, so I am leaving it out of the PR.

    Measured on \main\ (f94c2ef) with the pandas->numpy lock file below, before/after the parser change:

    before: deps = [] after: deps = [{pandas@3.0.6 [numpy@2.5.3]}]

    No change to any other test case in \pkg/dependency/parser/python/poetry.

  3. juliosuas commented on Nov 26, 2026

    @juliosuas
    Contributor

    Hi @DmitriyLewen, if nobody on the team has started on this I'd be happy to take it. Approach: parseDependency returns all matching IDs; constraints are read from all three forms (string, inline table, array of inline tables, skipping entries without version such as path/git); every locked version that satisfies any constraint gets an edge, because markers aren't evaluated. I'd add both reproductions from the issue as parser testdata and as analyzer testdata (checking that numpy stays a non-dev indirect dependency). Does linking every matching version match what you had in mind for case 2?

  4. DmitriyLewen commented on Nov 27, 2026

    @DmitriyLewen
    ContributorAuthor

    Hi @lxcxjxhx , @juliosuas ,

    sueun-dev has already worked on this task (he previously prepared a fix and opened a discussion). He mentioned he was ready to reopen the PR, so I am waiting for his reply.

    If there is no response from him in the near future, we will reassign the issue.

    Regards, Dmitriy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions