Repository navigation
fix(json): give on_start the object's own writer and pass the hooks to nested parse nodes - #807
Merged
Vincent Biret (baywet) merged 2 commits intoOct 15, 2026
Conversation
…o nested parse nodes JsonSerializationWriter called on_start_object_serialization with the outer writer, but the object is written into a temp writer. The backing store uses on_start to write null for properties set to None. So clearing a property on the root model raised "Invalid Json output", and on a nested model the null went into the parent object. on_start now gets the temp writer, which is the writer the object is written to, like in C#. JsonParseNode built each field's node without the before and after hooks, so they only ran for the root object. Field nodes now come from _create_new_node, which copies them, like the C# parse node.
Vincent Biret (baywet)
approved these changes
Oct 15, 2026
Vincent Biret (baywet)
left a comment
Member
There was a problem hiding this comment.
Thanks for the contribution!
|
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.



Overview
Two bugs in how the JSON package runs the serialization and parsing hooks. Both repros use this backed model:
JsonSerializationWritergaveon_start_object_serializationthe outer writer, but each object is written into a temp writer. The backing store useson_startto writenullfor properties set toNone, so those nulls land in the wrong object:on_startnow gets the writer the object is written to, like in C#. msgraph-sdk-python turns on the backing store in its client constructor, so a PATCH that clears a property goes through this.JsonParseNodebuilt each field's node without the before and after hooks, so they ran only for the root object:_create_new_nodecopies the hooks, like in C#, so field nodes now get them.Related Issue
No issue. Found while typing the proxy factories for #722 (#806).
Testing Instructions
pytestinpackages/serialization/jsonpasses. The three new tests fail without the source change.yapf -dr kiota_serialization_json,pylintandmypypass.mainand the "now" output on this branch.