Skip to content

Conversation

iamzimozic
Copy link
Contributor

Fixes #19992

Summary / Description:

Fix PydanticSerializationError when PostgresChatStore tries to store ChatMessage objects containing FunctionCall from Google’s Generative AI.

Added a helper safe_model_dump_json() to serialize non-standard objects safely.

Replaced all model_dump_json() calls in PostgresChatStore with safe_model_dump_json(message).

New Package?

Yes

✅ No

Version Bump?

Yes

✅No (change is internal to existing storage module)

Type of Change

✅Bug fix (non-breaking change which fixes an issue)

New feature

Breaking change

Requires documentation update

How Has This Been Tested?

✅ Added local test verifying safe_model_dump_json() works with FunctionCall.

✅ Verified PostgresChatStore.add_message() and get_messages() (local SQLite or Postgres) works end-to-end.

Suggested Checklist:

✅ Self-reviewed code

✅ Commented code in key areas (safe_model_dump_json)

Documentation updates not needed

No new notebooks added

✅ No new warnings generated

✅ Tests prove the fix works (serialization test)

✅ Existing unit tests pass locally

✅ Ran formatting/lint checks

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Oct 8, 2025
@anoopshrma
Copy link
Collaborator

You'll need to bump the version too for it to reflect once it gets merged

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 8, 2025
@iamzimozic
Copy link
Contributor Author

@anoopshrma Do I need to edit the GitHub workflow for the core-typecheck or is it something else you are referring to which I need to bump the version of?
Would appreciate your guidance.


params = {
"key": key,
"value": [message.model_dump_json() for message in messages],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the better fix here is fixing the pydantic model for the chat message

It already has handling for special objects in additional_kwargs, but probably is just missing a case to handle whatever type you are encountering with google

Copy link
Collaborator

Choose a reason for hiding this comment

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

@field_serializer("additional_kwargs", check_fields=False)

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Oct 8, 2025
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

3 participants