Skip to content

fix(scim): keep lists of plain values flat in snake_cased_body - #1973

Open
kwy404 wants to merge 6 commits into
slackapi:mainfrom
kwy404:fix-scim-snake-case-list-values
Open

kwy404 wants to merge 6 commits into
slackapi:mainfrom
kwy404:fix-scim-snake-case-list-values

Conversation

@kwy404

@kwy404 kwy404 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Summary

_convert_dict_keys (used by SCIMResponse.snake_cased_body) handles a list whose items are not dicts by appending _create_copy(original_value) for every element, so it copies the whole list once per element instead of copying the element. For a response like {"schemas": ["urn:scim:schemas:core:1.0"]}, schemas becomes [["urn:scim:schemas:core:1.0"]], and a list with two items becomes two copies of itself. As a result ReadUserResponse.user.schemas (and group.schemas on the group responses) is a nested list, and passing that user back to update_user sends "schemas": [["urn:scim:schemas:core:1.0"]].

The fix appends a copy of element instead. Lists of dicts go through the other branch and are unchanged.

Testing

Added test_snake_cased_list_of_plain_values to tests/slack_sdk/scim/test_internals.py. It fails before the change (the result is [[...], [...]]) and passes after. The SCIM test suites (sync and async), ruff format --check and ruff check were run locally.

Category

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.signature (Request Signature Verifier)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.models (UI component builders)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.rtm_v2 (RTM client)
  • /docs (Documents)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

_convert_dict_keys appended a copy of the whole list for every element of a
list that does not hold dicts, so a value like schemas: ["a", "b"] became
[["a", "b"], ["a", "b"]]. Append a copy of each element instead.
@kwy404
kwy404 requested a review from a team as a code owner October 1, 2026 16:10

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

Thanks for tracking this down!

One small request inline: a response-level assertion so the user-facing symptom is covered too. Happy to approve once CI runs green 🚀

result_dict[new_key].append(new_element)
else:
result_dict[new_key].append(_create_copy(original_value))
result_dict[new_key].append(_create_copy(element))

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.

praise: Nice catch, this is the right fix. Copying element instead of original_value keeps the list flat and leaves the list-of-dicts branch untouched.

Comment thread tests/slack_sdk/scim/test_internals.py Resolved
@WilliamBergamin WilliamBergamin added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch Version: 3x scim-client labels Oct 21, 2026
@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.76%. Comparing base (5c81bb1) to head (a6e2b93).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1973      +/-   ##
==========================================
+ Coverage   84.73%   84.76%   +0.02%     
==========================================
  Files         118      118              
  Lines       14129    14129              
==========================================
+ Hits        11972    11976       +4     
+ Misses       2157     2153       -4     

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

@kwy404

kwy404 commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Added the user.schemas assertion you suggested to test_snake_cased in test_response.py. I kept the snake_cased_body["schemas"] check next to it, since that is the one that fails on main. The CI workflows for the new commit need approval to run.

@mwbrooks mwbrooks added this to the 3.48.1 milestone Nov 24, 2026

@mwbrooks mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

✅ Thanks @kwy404 for tracking down the doubled schemas lists, and for following up on William's ask!

I'll bring the branch up to date with main and get CI running next.

)
user = response.users[0]
self.assertEqual(user.schemas, ["urn:scim:schemas:core:1.0"])
self.assertEqual(response.snake_cased_body["schemas"], ["urn:scim:schemas:core:1.0"])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

praise: Good call asserting on snake_cased_body["schemas"] here. It's the one that fails on main, and it's the same dict ReadUserResponse.user is built from, so the user-facing bug is pinned. 🙌

@mwbrooks

Copy link
Copy Markdown
Member

Updated the branch from main and the CI workflow is running now. I'll follow up here with the result.

@mwbrooks

Copy link
Copy Markdown
Member

CI is green across every Python version, with lint, typecheck, and codecov passing too. ✅

@WilliamBergamin the response-level assertion you asked for is in, so this is ready for a re-review when you have a moment. 🙏

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

bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented cla:signed scim-client semver:patch Version: 3x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants