You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When poetry remove <pkg> is run without--group, it deletes dependency groups from pyproject.toml that were empty before the command and are unrelated to the removed packages. The single-group path (--group X) already preserves such groups (test_remove_preserves_unrelated_empty_groups), but the remove-from-all-groups path does not.
Actual: exit 0, and [dependency-groups] docs = [] is silently removed from pyproject.toml. poetry lock alone preserves the group, so the deletion is caused by remove specifically.
Expected: the group is preserved, as it is with --group given.
The same happens for an empty legacy [tool.poetry.group.unrelated.dependencies] table. It also cascades: if the empty group is included by another group, e.g.
poetry remove six --lock deletes both groups (docs via the bug, dev via the include-reference cleanup), changing what poetry install --with dev resolves afterwards.
Cause
In src/poetry/console/commands/remove.py, the group is None branch runs the cleanup blocks for every group whenever the group's sections are empty after the removal loop:
if not poetry_section and "dependencies" in poetry_groups_content.get(group_name, {}) — deletes an already-empty legacy dependencies table
if not standard_section and group_name in groups_content — deletes an already-empty PEP 735 group
Neither check distinguishes "became empty because we removed its last dependency" (intended, and what the include-reference cleanup in #11141 builds on) from "was empty before the command" (unrelated side effect).
Impact
An unrelated command mutates the user's group declarations: groups disappear from pyproject.toml without any warning, and groups that only existed to be included elsewhere (--with/--group targets) vanish entirely.
I have a fix ready that gates the per-group cleanup on packages actually removed from that group, plus a parametrized regression test mirroring test_remove_preserves_unrelated_empty_groups for the remove-from-all-groups path.
Activity