Skip to content

fix(python): parse poetry dependencies with marker-specific constraints - #11058

Open
sueun-dev wants to merge 1 commit into
aquasecurity:mainfrom
sueun-dev:fix-poetry-array-deps
Open

fix(python): parse poetry dependencies with marker-specific constraints#11058
sueun-dev wants to merge 1 commit into
aquasecurity:mainfrom
sueun-dev:fix-poetry-array-deps

Conversation

@sueun-dev

Copy link
Copy Markdown
Contributor

Description

poetry.lock records a dependency as an array of inline tables when the same package is required with different version constraints per environment marker:

[package.dependencies]
typing-extensions = [
    {version = ">=4.6.0", markers = "python_version < \"3.15\""},
    {version = ">=4.14.0", markers = "python_version >= \"3.15\""},
]

parseDependency only handled the plain-string form (">=1.0") and the single inline-table form ({version = "..."}). The array form decodes to []any, matched neither case, and left the constraint empty, so the dependency edge was silently dropped from the graph. Poetry writes this form whenever a dependency is locked with different constraints per Python version or platform, so it turns up in real lockfiles.

The change moves constraint extraction into a versionRanges helper that also handles the array form, and matches the installed version against any of the listed constraints.

How I tested

Added testdata/poetry_multiple_constraints.lock where foo requires typing-extensions via the array form. In TestParser_Parse, foo's dependsOn is missing that edge before the change; TestParseDependency gets the array case too. Both fail before and pass after.

go test ./pkg/dependency/parser/python/...

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective.

poetry.lock records a dependency as an array of inline tables when the
same package is required with different constraints per environment
marker. parseDependency only handled the string and single inline-table
forms, so the array form left the constraint empty and the dependency
edge was silently dropped from the graph. Extract the constraint(s) in a
versionRanges helper that also handles the array form.

@nikpivkin nikpivkin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sueun-dev !

Please open a discussion before submitting a PR, where you describe the issue and include steps to reproduce it.

// poetry add pytest@5.4.3 --dev
// poetry show -a | awk '{gsub(/\(!\)/, ""); printf("{ID: \""$1"@"$2"\", Name: \""$1"\", Version: \""$2"\"},\n") }'
// mark dev deps
poetryMultipleConstraints = []ftypes.Package{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above, which contains commands for reproduction, refers to the poetryFlask variable, so they should not be separated.

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.

2 participants