Skip to content

Fix and correctly scope the Poetry package updater - #896

Merged
orto17 merged 8 commits into
jfrog:devfrom
orto17:feature/poetry-fix-support
Sep 27, 2026
Merged

orto17 merged 8 commits into
jfrog:devfrom
orto17:feature/poetry-fix-support

Conversation

@orto17

@orto17 orto17 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
  • The pull request is targeting the dev branch.
  • The code has been validated to compile successfully by running go vet ./....
  • The code has been formatted properly using go fmt ./....
  • All static analysis checks passed.
  • All tests have passed. If this feature is not already covered by the tests, new tests have been added.
  • Updated the Contributing page / ReadMe page / CI Workflow files if needed.
  • All changes are detailed at the description. if not already covered at JFrog Documentation, new documentation have been added.

handlePoetry ran poetry add <pkg>==<ver>, which rewrites whatever constraint form was declared (range, table-with-extras, group) into an exact pin, then a bare poetry update, which is unscoped (drifts unrelated transitives) and, without --lock, installs into the environment. It also ran in the process working directory rather than the project the finding's evidence points at.

Fix

Replaced with the verified sequence: pin the dependency to the exact fix version wherever its existing declaration actually is (bare string, table-with-extras, group table, or PEP 621 native array entry) — never via poetry add, which duplicates the dependency into the main table when it actually lives in a group (verified live). Then a scoped poetry update <pkg> --lock --no-interaction, restore the manifest verbatim, and re-sync the lock's content-hash without re-resolving (poetry lock on 2.x, poetry lock --no-update on 1.x — the flag's meaning inverted as Poetry 2.0's new default). If the original constraint doesn't admit the fix version, restoring it verbatim silently reverts the lock while poetry check --lock still exits 0 (verified with jinja2 ^2.11 and a fix of 3.1.6) — widen by re-applying the exact pin instead, and assert the locked version directly rather than trusting that exit code.

Runs via cmd.Dir resolved from the finding's evidence, never the process cwd, matching the existing Yarn/Go/Npm updaters' convention. Never sets cmd.Env, so private-index credentials are inherited from whatever environment the customer's own CI already provides.

Verification

  • Byte-identical preservation — dependency in [tool.poetry.dependencies] with a range that admits the fix version: pyproject.toml unchanged, only poetry.lock updates.
  • Widening — range doesn't admit the fix version (jinja2 ^2.11 → 3.1.6): constraint widened to the exact pin, locked version verified directly.
  • Group targeting — dependency in [tool.poetry.group.dev.dependencies]: fixed in place, no duplication into the main table (the bug poetry add has).
Scenario Result
Range admits fix version pyproject.toml byte-identical, poetry.lock updated
Range doesn't admit fix version Constraint widened, locked version verified
Dependency in a group table Fixed in place, no duplicate entry in main table

Added regression tests for all three, plus dedicated testdata fixtures. Existing poetry-direct-dep test updated to supply evidence, since the fix no longer relies on cwd. Full suite passes except a pre-existing, unrelated pipenv failure (binary not installed in this sandbox).

orto17 and others added 2 commits September 23, 2026 09:08
handlePoetry ran 'poetry add <pkg>==<ver>', which rewrites whatever
constraint form was declared (range, table-with-extras, group) into
an exact pin, then a bare 'poetry update', which is unscoped (drifts
unrelated transitives) and, without --lock, installs into the
environment. It also ran in the process working directory rather than
the project the finding's evidence points at.

Replaced with the verified sequence: pin the dependency to the exact
fix version wherever its existing declaration actually is (bare
string, table-with-extras, group table, or PEP 621 native array
entry) - never via 'poetry add', which duplicates the dependency into
the main table when it actually lives in a group (verified: reproduces
this with a [tool.poetry.group.dev.dependencies] entry). Then a scoped
'poetry update <pkg> --lock --no-interaction', restore the manifest
verbatim, and re-sync the lock's content-hash without re-resolving
('poetry lock' on 2.x, 'poetry lock --no-update' on 1.x - the flag's
meaning inverted as Poetry 2.0's new default). If the original
constraint doesn't admit the fix version, restoring it verbatim
silently reverts the lock while 'poetry check --lock' still exits 0
(verified with jinja2 "^2.11" and a fix of 3.1.6) - widen by
re-applying the exact pin instead, and assert the locked version
directly rather than trusting that exit code.

Runs via cmd.Dir resolved from the finding's evidence, never the
process cwd, matching the existing Yarn/Go/Npm updaters' convention.
Never sets cmd.Env, so private-index credentials are inherited from
whatever environment the customer's own CI already provides.

Added regression tests for all three verified scenarios (byte-identical
preservation, widening, and group-table targeting without duplication)
with dedicated testdata fixtures, plus updated the existing poetry test
case to supply evidence now that the fix no longer relies on cwd.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Cut the handlePoetry doc comment from 24 lines to 3, keeping only why
'poetry add' and a bare 'poetry update' are avoided and pointing to
fixPoetryDependency for the actual sequence. Removed the 5 test-function
doc comments added in this branch - the file's existing convention
(TestPipPackageRegex) has none.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 9df04f7c-af8d-4f8f-89f3-46847c6fad2f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@orto17 orto17 added the safe to test Approve running integration tests on a pull request label Sep 23, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Sep 23, 2026
gosec flagged G703 (CWE-22, path traversal via taint analysis) on the
four os.WriteFile calls in fixPoetryDependency that write to
descriptorPath, since it's a parameter ultimately derived from scan
evidence rather than a compile-time constant. G703 isn't in the
workflow's exclude list, so it needs an inline suppression per call,
same as the existing pattern already used for handlePip and handleUv's
equivalent writes.

Verified clean with gosec run locally using the exact CI flags, both
scoped to packageupdaters and across the full repo (Issues: 0 in both).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@orto17 orto17 added the safe to test Approve running integration tests on a pull request label Sep 23, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Sep 23, 2026
@orto17 orto17 added new feature Automatically generated release notes safe to test Approve running integration tests on a pull request labels Sep 23, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Sep 23, 2026

@Jordanh1996 Jordanh1996 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.

a

…arens format, multi-declaration and quote-style gaps

Fixes 6 issues raised on the Poetry package updater: a oneline PEP 621
array losing sibling deps to the shared range regex's unbounded match,
poetry.lock not being accepted as evidence (root cause was missing from
Poetry's packageDescriptors in techutils.go), the "name (>=x,<y)" form
Poetry 2 writes, manifest/lock name separator mismatches, only the first
of multiple declarations getting pinned, and single-quoted constraints.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@orto17 orto17 added the safe to test Approve running integration tests on a pull request label Sep 24, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Sep 24, 2026
@orto17
orto17 requested a review from Jordanh1996 September 24, 2026 08:11
orto17 and others added 2 commits September 27, 2026 09:47
…endencies

Handles 3 more gaps a teammate found: PEP 621 extras ("requests[socks]")
were dropped instead of preserved, an environment marker's embedded
single quote truncated the fix into invalid TOML, and Poetry's
multiple-constraints-dependencies form (name = [{...}, {...}]) wasn't
matched at all.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@orto17 orto17 added the safe to test Approve running integration tests on a pull request label Sep 27, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Sep 27, 2026
@orto17 orto17 added the safe to test Approve running integration tests on a pull request label Sep 27, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Sep 27, 2026
@orto17
orto17 merged commit f3431bd into jfrog:dev Sep 27, 2026
120 of 133 checks passed

This branch had an error being deployed

1 failed deployment
frogbot — d9e7a894 Deployed Sep 27, 2026 by orto17 via scan-pull-request #4600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature Automatically generated release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants