Skip to content

fix(workspace): keep declared group for workspace members in lockfile - #3819

Merged
frostming merged 4 commits into
pdm-project:mainfrom
Solaris-star:fix/3816-workspace-optional-dev-groups
Jul 26, 2026
Merged

fix(workspace): keep declared group for workspace members in lockfile#3819
frostming merged 4 commits into
pdm-project:mainfrom
Solaris-star:fix/3816-workspace-optional-dev-groups

Conversation

@Solaris-star

Copy link
Copy Markdown
Contributor

Description

Workspace members are always injected as implicit editable dependencies with groups = ["default"]. When a member is only declared in a non-default group (e.g. pdm add -dG test ./subproject), the lockfile still marked it as default (and sometimes both default and test).

Removing the workspace config made groups correct, so the bug is specifically the implicit default injection path.

Fix

  1. with_workspace_dependencies(..., exclude=...) — skip members already declared in other groups when injecting into default.
  2. _resolve_dependencies — compute declared_elsewhere and pass it as exclude.
  3. Resolver find_matchescopy_with(original_req) for workspace candidates so requirement groups follow the declared dependency.

Verification

Minimal workspace repro (pdm add -dG test ./subproject):

# pdm.lock excerpt
[[package]]
name = "subproject"
groups = ["test"]   # no longer includes "default"

Linked Issue

Closes #3816

Solaris-star and others added 2 commits July 21, 2026 12:03
Implicit workspace members were always injected into the default group
with groups=["default"]. When a member was only declared in a dev/test
group, lockfile metadata still listed default, which is wrong.

Skip members already present in non-default groups when injecting
implicit workspace deps, and associate the original requirement when
resolving workspace candidates.

Fixes pdm-project#3816
@frostming

Copy link
Copy Markdown
Collaborator

The tests are failed, please check @Solaris-star

@yangfan-yf-yf yangfan-yf-yf 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.

I reproduced the two CI failures on f01a437 locally on Windows:

py -m uv run pytest tests/cli/test_add.py::test_add_subdirectory_path_updates_workspace tests/test_project.py::test_workspace_member_declared_in_dev_group_not_forced_into_default -q
# 2 failed

The first failure is a regression from can.copy_with(original_req): the workspace candidate used by pdm add packages/foo is no longer editable. The same existing test passes on the current main branch, so the workspace candidate needs to retain its editable requirement while still carrying the declared dependency's group information.

The new test also calls project.get_dependencies(default). That resolves only the default group, so declared_elsewhere never sees the test dependency and the implicit workspace member is expected to be added. Please exercise the all-group lock-resolution path (or otherwise include the declared group in the resolution) when checking the lockfile group result.

Signed-off-by: Solaris-star <820622658@qq.com>
@Solaris-star

Copy link
Copy Markdown
Contributor Author

Thanks for the precise repro. I pushed ad919d74 with both fixes: the workspace candidate keeps its editable requirement while inheriting only the declared groups, and the regression test now resolves all groups and verifies the final lockfile records foo only in test. I also added the required news fragment. The two focused tests pass locally.

# Conflicts:
#	src/pdm/project/core.py
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.39%. Comparing base (7cb8367) to head (bd016a3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3819   +/-   ##
=======================================
  Coverage   86.39%   86.39%           
=======================================
  Files         121      121           
  Lines       13224    13227    +3     
  Branches     2244     2245    +1     
=======================================
+ Hits        11425    11428    +3     
  Misses       1185     1185           
  Partials      614      614           
Flag Coverage Δ
unittests 86.28% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@frostming
frostming merged commit 34e754e into pdm-project:main Jul 26, 2026
39 of 40 checks passed
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.

Workspace members are always treated as default dependencies

3 participants