Skip to content

fix(json): distinguish null from the none enum member - #762

Merged
Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
Shubham-Padkonde:fix/json-null-enum-values
Oct 5, 2026
Merged

Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
Shubham-Padkonde:fix/json-null-enum-values

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown
Contributor

Overview

Preserve JSON null when parsing an enum that has a None_ = "none" member. Currently str(None) becomes "None", which takes the reserved-keyword handling path and returns the actual enum member. A missing value can therefore be mistaken for an explicitly supplied "none" value.

Return None before converting a null node to text. The wire value "none" still resolves to None_, and ordinary enum values are unchanged. Collection entries use the same correction.

Related Issue

No separate issue found. The regression is reproduced by JsonParseNode(None).get_enum_value() with an enum containing None_ = "none".

Testing Instructions

  • Install the local abstractions and JSON serialization packages and the JSON package's test dependencies.
  • From packages/serialization/json, run python -m pytest tests -q: all 200 tests pass.
  • The scalar-null and null-collection-entry regressions both fail before the fix; explicit "none" and "low" remain valid.
  • Mypy passes for all six source files; YAPF reports no changes for the edited source and new tests.

Pylint rates the source 10/10 but reports the existing suggestion-mode configuration option as unrecognized in the installed version.

@sonarqubecloud

sonarqubecloud Bot commented Oct 4, 2026

Copy link
Copy Markdown

@baywet Vincent Biret (baywet) 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 for the contribution!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The localized fix preserves non-null behavior and includes focused regression coverage with no unresolved findings.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes JSON enum parsing so null remains Python None rather than resolving to the enum member None_.

Changes:

  • Returns early for null nodes, preserving non-null behavior.
  • Adds scalar and collection regression tests.
File Description
packages/​serialization/​json/​tests/​unit/​test_nullable_enum.py Tests null entries and explicit enum values.
packages/​serialization/​json/​kiota_serialization_json/​json_parse_node.py Handles null before converting enum values to text.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@baywet
Vincent Biret (baywet) merged commit 9f98830 into microsoft:main Oct 5, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

3 participants