Skip to content

Fixing _sign_in_state serialization/deserialization#264

Merged
rodrigobr-msft merged 3 commits intomainfrom
users/robrandao/sign-in-state-issue
Dec 1, 2025
Merged

Fixing _sign_in_state serialization/deserialization#264
rodrigobr-msft merged 3 commits intomainfrom
users/robrandao/sign-in-state-issue

Conversation

@rodrigobr-msft
Copy link
Contributor

This pull request refactors the _SignInState class to use Pydantic for data modeling and validation, simplifying serialization and deserialization logic. It also updates related test utilities and adds a new test to verify the correctness of the new serialization approach.

Refactoring and code improvements:

  • Refactored the _SignInState class in _sign_in_state.py to inherit from pydantic.BaseModel alongside StoreItem, removing the manual __init__ and leveraging Pydantic's model-based serialization and validation methods (model_dump, model_validate).
  • Updated the store_item_to_json and from_json_to_store_item methods in _SignInState to use Pydantic's serialization/deserialization utilities, streamlining the code and improving maintainability.

Testing improvements:

  • Added a new test test_sign_in_state_serialization_deserialization in test_sign_in_state.py to ensure that _SignInState objects can be correctly serialized to and deserialized from JSON, including file round-tripping.
  • Updated the create_testing_TurnContext utility in _common.py to construct the Activity object directly, aligning with the updated data model.

Copilot AI review requested due to automatic review settings December 1, 2025 18:05
@rodrigobr-msft rodrigobr-msft linked an issue Dec 1, 2025 that may be closed by this pull request
@rodrigobr-msft rodrigobr-msft marked this pull request as ready for review December 1, 2025 18:05
@rodrigobr-msft rodrigobr-msft requested a review from a team as a code owner December 1, 2025 18:05
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 pull request successfully refactors the _SignInState class to use Pydantic's BaseModel for improved data modeling, validation, and serialization. The changes align with the existing pattern used in _FlowState and modernize the codebase by leveraging Pydantic's built-in capabilities.

Key changes:

  • Converted _SignInState from manual initialization to Pydantic field declarations, eliminating boilerplate code
  • Replaced manual dictionary construction with Pydantic's model_dump() and model_validate() methods for serialization/deserialization
  • Added comprehensive test coverage for the new serialization mechanism, including file-based round-trip testing

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/oauth/_sign_in_state.py Refactored to use Pydantic BaseModel with field annotations, replacing manual __init__ and dict-based serialization with model_dump() and model_validate()
tests/hosting_core/app/_oauth/test_sign_in_state.py Added new test verifying serialization/deserialization correctness, including JSON file round-trip validation
tests/hosting_core/app/_oauth/_common.py Improved test utility by constructing real Activity objects instead of using mock attribute assignment

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

Copilot AI review requested due to automatic review settings December 1, 2025 20:33
@rodrigobr-msft rodrigobr-msft merged commit 84af516 into main Dec 1, 2025
13 of 14 checks passed
@rodrigobr-msft rodrigobr-msft deleted the users/robrandao/sign-in-state-issue branch December 1, 2025 20:35
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

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


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

rodrigobr-msft added a commit that referenced this pull request Dec 1, 2025
* Fixing _sign_in_state (de)serialization

* Reformatting

---------

Co-authored-by: Chris Mullins <cleemullins@users.noreply.github.com>
rodrigobr-msft added a commit that referenced this pull request Dec 1, 2025
* Getting package version from file when building packages (#261)

* Writing version to file and reading it when building

* Fixing issue

* Removed unnecessary declaration

* Specifying encoding

* Adding MANIFEST.in file to include package version files in builds (#263)

* Writing version to file and reading it when building

* Fixing issue

* Removed unnecessary declaration

* Specifying encoding

* Adding MANIFEST.in files to include VERSION.txt

* Fixing _sign_in_state serialization/deserialization (#264)

* Fixing _sign_in_state (de)serialization

* Reformatting

---------

Co-authored-by: Chris Mullins <cleemullins@users.noreply.github.com>

---------

Co-authored-by: Chris Mullins <cleemullins@users.noreply.github.com>
Copilot AI mentioned this pull request Dec 2, 2025
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.

Fails to save agent state: _SignInState is not JSON serializable

2 participants

Comments