Skip to content

fix(add, remove): match --group against existing groups by normalized name - #11193

Open
RaphaelFakhri wants to merge 1 commit into
python-poetry:mainfrom
RaphaelFakhri:fix/add-remove-normalized-group-name
Open

RaphaelFakhri wants to merge 1 commit into
python-poetry:mainfrom
RaphaelFakhri:fix/add-remove-normalized-group-name

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Pull Request Check List

Resolves: #11192

  • Added tests for changed code.
  • Updated documentation for changed code.

Summary

poetry add --group and poetry remove --group compare the given group name against the keys in pyproject.toml literally. When pyproject.toml declares a group as My_Group:

  • poetry remove --group my-group <pkg> fails with The following packages were not found.
  • poetry add --group my-group <pkg> adds a separate my-group group. Poetry then rejects the project with Duplicate dependency group name after normalization.

This change resolves --group to the existing key in [dependency-groups] or [tool.poetry.group] by comparing normalized names. If no group matches, the name is used as given, so new groups are created as before.

Tests

  • test_add_to_existing_group_with_non_normalized_name (PEP 735 and legacy group)
  • test_remove_from_group_with_non_normalized_name (PEP 735 and legacy group)

All four tests fail without the change and pass with it.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Linked issues

#11192 `poetry add --group` and `poetry remove --group` do not match normalized group names · 1 of 2 met

# Requirement Status Notes
1 poetry add --group targets an existing normalized group name in either group section. 🟡 Partly met The resolver finds existing names in both sections, but when a legacy group is selected and [dependency-groups] contains another group, add routes the dependency into [dependency-groups] and can create a duplicate normalized group.
2 poetry remove --group targets an existing normalized group name in either group section. ✅ Met The selected group is resolved against both [dependency-groups] and [tool.poetry.group] before removal.

Sourcery assessment

Needs a human reviewer. If two declared group keys normalize to the same name, the first match can cause add or remove to edit the unintended group. The resulting manifest (and potentially lockfile) change persists after a revert, but is bounded and can be corrected manually.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
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.

poetry add --group and poetry remove --group do not match normalized group names

1 participant