Skip to content

[CHA-2716] Ignore null fields#224

Merged
mogita merged 3 commits intomainfrom
fix/null-fields
Mar 19, 2026
Merged

[CHA-2716] Ignore null fields#224
mogita merged 3 commits intomainfrom
fix/null-fields

Conversation

@mogita
Copy link
Contributor

@mogita mogita commented Mar 19, 2026

Summary by CodeRabbit

  • Documentation

    • Added migration guide clarifying that optional unset fields are omitted from JSON requests (v2→v3), while provided empty lists/dicts are still serialized.
  • Improvements

    • JSON request handling now omits unset optional fields instead of sending explicit nulls, avoiding unintended resets on partial updates.
  • Tests

    • Added unit tests verifying None values are stripped correctly and empty collections are preserved in nested structures.

@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2026

📝 Walkthrough

Walkthrough

Adds a recursive _strip_none helper and applies it to JSON payloads in synchronous and asynchronous request helpers so unset (None) optional fields are omitted from request bodies; updates migration docs and adds tests covering the new stripping behavior.

Changes

Cohort / File(s) Summary
Documentation
MIGRATION_v2_to_v3.md
Documents JSON serialization behavior change: unset optional fields are omitted instead of serialized as null; provided collections (including empty []/{}) remain serialized.
Request Serialization
getstream/base.py
Adds internal _strip_none helper to recursively remove None from dicts/lists and integrates it into _request_sync and _request_async to transform non-None json payloads before sending.
Tests
tests/test_decoding.py
Adds unit tests for _strip_none: strips None from flat and nested dicts, preserves empty collections, handles lists (retains elements, strips None inside dicts within lists), and leaves non-dict scalars unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nudge the keys where None did hide,
I hop through lists and nests inside.
Quiet payloads, tidy and bright—
No more nulls to spoil the night. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Ignore null fields' directly describes the main change: omitting unset (None) fields from JSON request bodies instead of serializing them as null.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/null-fields
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the HTTP client layer to omit unset optional fields (None) from JSON request bodies, preventing accidental backend resets during partial updates, and documents the behavior change in the v2→v3 migration guide.

Changes:

  • Add a recursive helper to strip None values from JSON payloads before sending requests (sync + async).
  • Apply the stripping logic to all requests that use kwargs["json"].
  • Document the new “omit unset optionals” serialization behavior in MIGRATION_v2_to_v3.md.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
getstream/base.py Strips None values from JSON bodies in both sync and async request paths.
MIGRATION_v2_to_v3.md Adds migration guidance explaining omitted optional fields vs explicit null.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@getstream/base.py`:
- Around line 28-35: _strip_none currently filters dict entries based on the
original value and maps lists without removing None results, so None elements
inside lists (and dict values that become None after recursion) remain
serialized; update _strip_none to recurse first then filter out None results: in
the dict branch call _strip_none(v) into a temporary (e.g., v2) and include the
key only if v2 is not None, and in the list branch build a list of
_strip_none(item) results and exclude any that are None (e.g., [r for r in
(_strip_none(i) for i in obj) if r is not None]) so no None/null values are
emitted in nested structures.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d9440083-bc67-436d-a49b-c2b67d0cef3a

📥 Commits

Reviewing files that changed from the base of the PR and between bc6024c and 1f106ba.

📒 Files selected for processing (2)
  • MIGRATION_v2_to_v3.md
  • getstream/base.py

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/test_decoding.py (1)

341-364: Group the new _strip_none tests into a dedicated test class.

Please group these related tests (e.g., class TestStripNone:) to match test organization standards for this repository.

As per coding guidelines, **/test_*.py: Keep tests well organized and use test classes to group similar tests.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_decoding.py` around lines 341 - 364, Group the standalone
`_strip_none` tests into a dedicated test class by creating `class
TestStripNone:` and moving the functions `test_strip_none_flat_dict`,
`test_strip_none_nested_dict`, `test_strip_none_preserves_empty_collections`,
`test_strip_none_preserves_list_elements`, and
`test_strip_none_passthrough_scalars` inside it, converting each into instance
methods (add a `self` parameter) and adjusting indentation; keep the test names
and assertions unchanged so they continue to call `_strip_none`.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/test_decoding.py`:
- Around line 341-364: Group the standalone `_strip_none` tests into a dedicated
test class by creating `class TestStripNone:` and moving the functions
`test_strip_none_flat_dict`, `test_strip_none_nested_dict`,
`test_strip_none_preserves_empty_collections`,
`test_strip_none_preserves_list_elements`, and
`test_strip_none_passthrough_scalars` inside it, converting each into instance
methods (add a `self` parameter) and adjusting indentation; keep the test names
and assertions unchanged so they continue to call `_strip_none`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0c5eb132-dd0b-491a-93b4-f2a2ec07eba1

📥 Commits

Reviewing files that changed from the base of the PR and between 1f106ba and 97bf1e6.

📒 Files selected for processing (1)
  • tests/test_decoding.py

@mogita mogita merged commit bc2b6de into main Mar 19, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants