Repository navigation
fix: preserve explicit None in Python dataclass tool arguments - #1605
Conversation
Signed-off-by: Eric Evans II <[email protected]>
Findings
|
| Layer / File(s) | Summary |
|---|---|
Null preservation and codec coverage python/nemo_relay/typed.py, python/tests/test_typed.py, docs/integrate-into-frameworks/using-codecs.mdx |
The serializer can preserve None fields through nested values, and DataclassCodec.to_json enables this behavior. Tests cover explicit and omitted nullable fields, tool callbacks, and BestEffortAnyCodec. Documentation describes encoding and decoding behavior. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
- NVIDIA/NeMo-Relay#1604 — The PR addresses the issue’s objective by preserving explicit
Nonevalues throughDataclassCodecconversion and testing callback behavior and omitted-field defaults.
Merge Risk: 
Low · up to b5b31
-
Explicit None values for ordinary dataclass fields are now preserved correctly. However, dataclasses with fields declared init=False can lose non-null values from nested payloads or fail to decode when they use a custom constructor. Restrict null preservation to init=True fields and keep the previous behavior for non-null values before merging.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
Issue
#1604requirements are met.DataclassCodec.to_json()enables null preservation, and_serialize_value()propagates it through nested dataclasses, lists, and dictionaries. The serializer preservesNoneforinit=Truefields, so explicitNonereachesDataclassCodec.from_json()and the tool callback. It omitsinit=Falsefields because the constructor cannot accept them. Omitted fields still use defaults or raiseTypeErrorwhen required. Non-null values andBestEffortAnyCodecbehavior remain unchanged. Tests cover codec conversion, tool callbacks, nested values, omitted fields, and compatibility. The guide documents the null-versus-omitted behavior.
Full details: Out of Scope Changes check
-
Explanation
The changed source, tests, and codec guide support issue
#1604. The implementation change is limited toDataclassCodecnull-field serialization and its nested value path. The regression tests verify the required behavior and preserve unrelatedBestEffortAnyCodecbehavior. The documentation explains the resulting codec contract. No unrelated change is demonstrated.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Signed-off-by: Eric Evans II <[email protected]>
|
/merge |
#### Overview Backport #1605 to `release/0.11` so the 0.11 patch release preserves explicitly supplied `None` in dataclass tool arguments. - [x] I confirm this contribution is my own work, or I have the right to submit it under this project's license. - [x] I searched existing issues and open pull requests, and this does not duplicate existing work. #### Details Applies the exact three-file patch from #1605, squash-merged on `main` as 4ff4ac2, without release-specific adaptations. - Preserve null fields when encoding dataclass arguments, including nested dataclasses, lists, and dictionaries. - Preserve existing best-effort encoding, defaults for omitted fields, and errors for omitted required fields. - Include the original regression tests and codec documentation. Public signatures are unchanged. Serialized dataclass JSON includes null fields that were previously omitted. Validation on `release/0.11` at 8e324ad plus this backport: - `just test-python`: passed — 86 native-binding tests, 1,310 Python tests, and 24 example tests. - `just docs`: passed, including four documentation-example tests. The published-redirect comparison was skipped because the Fern service returned HTTP 403. - All applicable commit hooks passed, including Ruff, typing, documentation links, and dependency audits. - The commit has a verified local GPG signature and DCO sign-off. #### Where should the reviewer start? Review [the original fix in #1605](#1605), then confirm this PR contains the same changes to `python/nemo_relay/typed.py`, `python/tests/test_typed.py`, and `docs/integrate-into-frameworks/using-codecs.mdx`. #### Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to) - Relates to #1604. - Backport of #1605; the fix is already merged into `main`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Python `DataclassCodec` now preserves fields explicitly set to `None` as JSON `null`, including in nested dataclasses, lists, and dictionaries. * Decoding uses defaults for omitted fields, raises `TypeError` for omitted required fields, and keeps explicit `null` as `None`. * **Documentation** * Clarified how nullable and omitted dataclass fields behave during encoding and decoding. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Eric Evans II <[email protected]>
Overview
Preserve explicitly supplied
Nonewhentyped.tool_execute()converts dataclass tool arguments. Previously, nullable fields could be dropped during conversion, causing a default to replace the supplied value or a missing-argumentTypeErrorbefore the callback ran.Details
DataclassCodec, including nested dataclasses, lists, and dictionaries.BestEffortAnyCodecbehavior.Public signatures are unchanged. Serialized dataclass JSON now includes null fields that were previously omitted.
Validation
just test-python: 81 native-binding tests, 1,304 Python tests, and 24 plugin example tests passed with isolated test configuration.just test-python-plugin-e2e: all 3 selected tests passed.just check-quickstarts: 12 tests passed and 11 contracts validated. Package-assembly and documentation-retention unit tests also passed.just docsand all applicable commit hooks passed. Fern’s comparison with published redirects was unavailable because its service returned HTTP 403.Local validation used macOS ARM64 and Python 3.13.1. Product CI remains pending.
Where should the reviewer start?
Start with DataclassCodec.to_json(), then the codec regression tests and tool callback coverage.
Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
Summary by CodeRabbit
Nonevalues as JSONnull, including in nested dataclasses, lists, and dictionaries.nullremainsNoneand does not trigger a default.None; non-null values are retained.