Fix skip_none parameter propagation to nested objects#657
Merged
Conversation
The skip_none parameter was not being passed to nested dataclasses, unions, and other serializable objects during serialization. This caused None values in nested objects to still be serialized as null even when skip_none=True was specified. Changes: - Update dataclass serialization calls to pass skip_none parameter - Update union template and function calls to support skip_none - Update Any type serialization to include skip_none parameter - Add comprehensive test coverage for nested skip_none behavior - Update code generation tests to match new function signatures Fixes #651 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull Request Overview
This pull request fixes the propagation of the skip_none parameter to nested objects during serialization. Previously, when skip_none=True was specified at the top level, None values in nested dataclasses, unions, and other serializable objects would still be serialized as null instead of being skipped.
- Updates serialization function signatures to include
skip_noneparameter - Ensures
skip_noneis passed through to all nested serialization calls - Adds comprehensive test coverage for nested skip_none behavior
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
serde/se.py |
Updates function templates and renderer methods to pass skip_none parameter to nested serialization calls |
tests/test_se.py |
Updates test kwargs string to include skip_none parameter |
tests/test_json.py |
Adds comprehensive tests for skip_none behavior with nested objects, unions, and lists |
| res = "None" | ||
| elif is_any(arg.type) or is_bearable(arg.type, TypeVar): | ||
| res = f"to_obj({arg.varname}, True, False, False, c=typing.Any)" | ||
| res = f"to_obj({arg.varname}, True, False, False, skip_none, typing.Any)" |
There was a problem hiding this comment.
The function call to to_obj has positional parameters mixed with a keyword-like parameter name skip_none. This inconsistency could lead to confusion. Consider using named parameters for all arguments or ensure the parameter order matches the function signature.
Suggested change
| res = f"to_obj({arg.varname}, True, False, False, skip_none, typing.Any)" | |
| res = f"to_obj({arg.varname}, True, False, False, skip_none=skip_none, typing.Any)" |
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.
The skip_none parameter was not being passed to nested dataclasses, unions, and other serializable objects during serialization. This caused None values in nested objects to still be serialized as null even when skip_none=True was specified.
Changes:
Fixes #651
🤖 Generated with Claude Code