Repository navigation
Fix add_user_to_groups replacing a user's existing groups - #1490
Merged
MariusWirtz merged 1 commit intoOct 14, 2026
Merged
Conversation
On recent TM1 versions (e.g. 11.8), PATCH /Users('x') with
Groups@odata.bind replaces the user's group collection instead of
appending to it, so add_user_to_groups dropped every group that was not
passed in.
Read the user's current groups and bind the union of current and new
groups. This behaves identically whether the server treats the bind as
append or replace, matching how update_user already sends the full list.
Groups the user already belongs to are skipped (case and space
insensitive), and kwargs are now forwarded to determine_actual_group_name.
Add tests asserting existing memberships survive and that re-adding an
existing group does not duplicate it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SecurityService.add_user_to_groupssendscontaining only the groups passed in. On Planning Analytics 2.x / TM1 Server 11.8 (observed on 11.8.3700), this PATCH replaces the user's whole group collection rather than appending to it. The user silently loses every group that was not in the call.
Reproduced with TM1py 2.2.5 and 2.3.1;
masterhas the same code.Minimal repro
Fix
add_user_to_groupsnow reads the user's current groups and binds the union of current and requested groups in a single PATCH:Groups@odata.bindas append or replace.update_useralready relies on sending the full group list.CaseAndSpaceInsensitiveSet), so re-adding a group doesn't duplicate it.**kwargsare now forwarded todetermine_actual_group_name. They weren't before.Response) are unchanged.Tests
Added to
Tests/SecurityService_test.py:test_add_user_to_groups_keeps_existing_groups: the user starts inGroup1,Group2is added, and both memberships are asserted.test_add_user_to_groups_already_member: re-adding an existing group (different case) together with a new group leaves exactly one membership for the existing group and adds the new one.ruff checkandblack --checkpass on the changed files. The live-server tests weren't run against a TM1 instance as part of this PR. The new logic was checked offline against a mockedRestService: current[A, B]plus requested["c", " b ", "C"]produces the bind list[A, B, C].🤖 Generated with Claude Code