Skip to content

Python: Respect exclude and exclude_none in BaseChatClient.to_dict for additional_properties - #9943

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
hardikkaurani:fix/python-base-chat-client-to-dict-exclude
Nov 4, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
hardikkaurani:fix/python-base-chat-client-to-dict-exclude

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Motivation & Context

In agent-framework (Python), BaseChatClient.to_dict accepts exclude and exclude_none (defaulting to True) parameters to control serialization. However, BaseChatClient.to_dict previously performed result.update(self.additional_properties) unconditionally at the end of serialization.

Because this update bypassed the serialization parameters:

  1. Passing exclude={"additional_properties"} or specifying a key present in additional_properties failed to exclude it.
  2. Keys with None values in additional_properties were unconditionally added to the output dictionary even when exclude_none=True (the default).

Description & Review Guide

  • What are the major changes?

    1. Updated BaseChatClient.to_dict to check exclude before promoting additional_properties to the root dictionary.
    2. Filtered entries in additional_properties so that keys matching exclude or having None values (when exclude_none=True) are excluded.
    3. Added unit tests in packages/core/tests/core/test_clients.py covering default exclusion of None, preserving None when exclude_none=False, excluding all additional properties via exclude={"additional_properties"}, and excluding individual property keys.
  • What is the impact of these changes?

    • Consistent serialization honoring exclude and exclude_none options across all client properties.
    • Zero breaking changes.

Related Issue

Fixes #9940

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change.

cc Eduard van Valkenburg (@eavanvalkenburg)

…ies in BaseChatClient.to_dict

Ensure BaseChatClient.to_dict respects exclude and exclude_none parameters when promoting additional_properties to the root level, avoiding leaking excluded fields or None values into serialized dictionaries.

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…nd exclude_none

Add unit test coverage verifying that BaseChatClient.to_dict correctly respects exclude_none (omitting None entries by default) and exclude sets (filtering either individual property keys or all additional_properties).

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Nov 1, 2026
@eavanvalkenburg

Copy link
Copy Markdown
Member

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

MAF Automated Review — Iteration 1

Result: No findings
Scope: full PR (2 commit(s)): 379c6e8cde30, 055be3646bae
Model: gpt-5.6-sol

Overview

The change filters flattened additional_properties against both caller exclusions and exclude_none while retaining the existing serialization flow. The added tests cover default null omission, explicit null preservation, whole-container exclusion, and individual-key exclusion. No Critical, High, or Medium regression introduced by this PR was established.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.

Merged via the queue into microsoft:main with commit 39dc737 Nov 4, 2026
55 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — 055be364 Deployed Nov 1, 2026 by hardikkaurani via team_check #8263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: BaseChatClient.to_dict ignores exclude and exclude_none for additional_properties

3 participants