fix(serialization-json): handle CSV string in get_collection_of_enum_values for flags enums - #516
Conversation
…values for flags enums Flags enums marked with x-ms-enum-flags in OpenAPI metadata are serialized as comma-separated strings by the Microsoft Graph API (e.g. "deviceCodeFlow" or "deviceCodeFlow,authenticationTransfer"), but get_collection_of_enum_values only accepted list inputs, silently returning [] for string values. This caused ConditionalAccessAuthenticationFlows.transferMethods in the Microsoft Graph SDK to always deserialize as an empty list. Fixes microsoft#515
The Microsoft Graph Python SDK (via kiota-serialization-json) incorrectly deserializes transferMethods in ConditionalAccessAuthenticationFlows, always returning an empty list. This is caused by get_collection_of_enum_values not handling CSV-serialized flags enums (microsoft/kiota-python#515). Fetch raw JSON and parse transferMethods manually as a workaround until the upstream fix (microsoft/kiota-python#516) is released.
@microsoft-github-policy-service agree company="Prowler" |
The Microsoft Graph Python SDK (via kiota-serialization-json) incorrectly deserializes transferMethods in ConditionalAccessAuthenticationFlows, always returning an empty list. This is caused by get_collection_of_enum_values not handling CSV-serialized flags enums (microsoft/kiota-python#515). Fetch raw JSON and parse transferMethods manually as a workaround until the upstream fix (microsoft/kiota-python#516) is released.
Vincent Biret (baywet)
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
The TextParseNode most likely has the same issue. Would you mind double checking and replicating the fix if necessary please?
Hugo Pereira Brito (HugoPBrito)
left a comment
There was a problem hiding this comment.
Thanks for the review Vincent Biret (@baywet)!
I checked both TextParseNode and FormParseNode:
-
TextParseNode.get_collection_of_enum_values()(line 149-154) raisesException("Text does not support structured data")— it doesn't attempt to parse at all, so it's not affected by this bug. -
FormParseNode.get_collection_of_enum_values()(line 186-199) already doesself._node.split(',')sinceself._nodeis always a string in form-urlencoded data. It correctly handles CSV values already.
So the issue was specific to JsonParseNode, where the value comes from json.loads() and the method only checked for isinstance(self._json_node, list), missing the case where JSON represents a flags enum as a plain string value (not an array).
Let me know if you'd like me to adjust anything!
Vincent Biret (baywet)
left a comment
There was a problem hiding this comment.
Thanks for confirming!
There was a problem hiding this comment.
Pull request overview
Fixes deserialization of flags enums serialized as CSV strings by adding string handling to get_collection_of_enum_values() in JsonParseNode.
Changes:
- Added CSV string parsing logic to
get_collection_of_enum_values()for flags enums - Added 5 new test cases covering CSV strings, single values, empty strings, spaces, and unknown members
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
packages/serialization/json/kiota_serialization_json/json_parse_node.py |
Added str handling branch to parse comma-separated enum values |
packages/serialization/json/tests/unit/test_json_parse_node.py |
Added 5 tests for the new CSV string parsing behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
Hugo Pereira Brito (@HugoPBrito) can you fix the formatting before we merge this PR please? |
|
Sure! I'm on it. |
|
Vincent Biret (baywet)
left a comment
There was a problem hiding this comment.
Thanks for the contribution!



Summary
Fixes #515
get_collection_of_enum_values()inJsonParseNodesilently returns[]when the JSON node is a string instead of a list. This breaks deserialization of flags enums that are serialized as comma-separated strings by the API (e.g."deviceCodeFlow"or"deviceCodeFlow,authenticationTransfer").Problem
Flags enums marked with
x-ms-enum-flags: isFlags: truein OpenAPI metadata are generated by Kiota to useget_collection_of_enum_values()as their deserializer (microsoft/kiota#3237). However, the Microsoft Graph API serializes these as CSV strings, not JSON arrays.The current code:
This directly affects
ConditionalAccessAuthenticationFlows.transferMethodsin the Microsoft Graph SDK, which always deserializes as[]regardless of the actual API response.Fix
Added CSV string handling after the existing
listcheck:The fix is backward-compatible — behavior for
listinputs is completely unchanged.Tests
5 new test cases added covering:
"dunhill,oval")"dunhill, oval")"dunhill")"")"dunhill,unknownValue,oval"— unknown values silently skipped)All 86 tests pass (81 existing + 5 new), zero regressions.
Verification
"transferMethods": "deviceCodeFlow"as a string (not an array)ConditionalAccessAuthenticationFlowsinmsgraph-sdkv1.23.0main(v1.9.9)