Repository navigation
Description
Title
JSON and text enum readers do not honor serialized wire values
Environment
- Python 3.13.7, Windows 11
microsoft-kiota-abstractions, JSON and text packages: 1.17.0 from currentmain, commit45012c132fd9d996718e6a50fe16d507a3562b8e
Describe the bug
An enum value written by Kiota does not necessarily deserialize to the same member. The JSON and text readers derive a Python member name from the serialized string rather than first resolving the member by its value. With different member names and wire values, JSON can return None or a different valid member, while text can throw for a value produced by its own writer.
To Reproduce
Install the JSON and text serialization packages and run this public-API-only example:
import sys, platform
from enum import Enum
from kiota_serialization_json.json_serialization_writer import JsonSerializationWriter
from kiota_serialization_json.json_parse_node_factory import JsonParseNodeFactory
from kiota_serialization_text.text_serialization_writer import TextSerializationWriter
from kiota_serialization_text.text_parse_node_factory import TextParseNodeFactory
class Status(Enum):
NotStarted = "not-started"
Ready = "running"
Running = "ready"
for member in [Status.NotStarted, Status.Ready]:
writer=JsonSerializationWriter();writer.write_enum_value("status",member)
body=writer.get_serialized_content()
print("JSON",repr(body),JsonParseNodeFactory().get_root_parse_node("application/json",body).get_child_node("status").get_enum_value(Status))
writer=TextSerializationWriter();writer.write_enum_value(None,Status.NotStarted)
body=writer.get_serialized_content()
try: print("text",TextParseNodeFactory().get_root_parse_node("text/plain",body).get_enum_value(Status))
except Exception as error: print(type(error).__name__+": "+str(error))Actual output:
JSON b'{"status": "not-started"}' None
JSON b'{"status": "running"}' Status.Running
Exception: Invalid key: Not-started for enum <enum 'Status'>.
Expected behavior
The first JSON value and the text value should deserialize to Status.NotStarted. The second JSON value should deserialize to Status.Ready, whose serialized value is "running".
Additional context
The Python generator explicitly emits each option's wire name as the enum value in CodeEnumWriter. Its tests also cover a SerializationName distinct from the Python option name. A member name and a wire value are therefore not interchangeable.
I reproduced this against untouched current main through the public writers and parse-node factories. Focused local regressions fail for nonmatching names/values, empty or escaped wire strings, JSON arrays and CSV enum inputs; existing known spellings, unknown values and JSON null controls pass. I have not established when this behavior was introduced.
I plan a focused fix that resolves the declared enum value first and retains the current member-name fallback, none/None_ handling and unknown-value behavior. Regression coverage should verify writer/reader round trips and keep those existing compatibility cases passing.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone ✔️
Activity