Skip to content

fix: keep subclasses in the remaining content part from_dict methods - #13605

Open
simin-yuan wants to merge 2 commits into
deepset-ai:mainfrom
simin-yuan:fix/content-part-from-dict-subclasses
Open

simin-yuan wants to merge 2 commits into
deepset-ai:mainfrom
simin-yuan:fix/content-part-from-dict-subclasses

Conversation

@simin-yuan

@simin-yuan simin-yuan commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

ToolCall, ToolCallResult and ReasoningContent in haystack.dataclasses.chat_message, and ToolCallDelta and
ComponentInfo in haystack.dataclasses.streaming_chunk, are content parts whose from_dict hardcoded its own class
(return ToolCall(**data)). Called on a subclass, it returned a base-class instance, so any extra field the subclass
carries was silently dropped after a to_dict() / from_dict() round trip.

They now instantiate cls(**data) and are annotated -> Self, the same shape TextContent, FileContent and
ImageContent got in #13536, and ByteStream got in #13180. Base-class behaviour is unchanged: the content-part
registry in _deserialize_content_part still looks up the base classes.

How did you test it?

One regression test per class, each defining a trivial @dataclass subclass and asserting
type(Sub.from_dict(Sub(...).to_dict())) is Sub.

  • Before the fix: 5 failed, 1 passed (the pass is the existing test_text_content_subclass_from_dict from fix: keep subclasses in content part from_dict #13536).
  • After the fix: 203 passed for test/dataclasses/test_chat_message.py test/dataclasses/test_streaming_chunk.py.
  • Full pytest test/dataclasses: 370 passed, 2 failed. Both failures are pre-existing on this Windows machine and
    unrelated to this change: test_from_file_path_guess_mime_type[spam.csv-...] reads the local CSV mime mapping, and
    test_image_content_show_in_jupyter needs IPython, which isn't installed here.

Notes for the reviewer

  • ToolCallResult.from_dict now builds cls(...), but its nested origin is still deserialized as the base
    ToolCall, because the serialized payload carries no type information for that field. Adding a type key there is a
    larger change; happy to do it separately if you want it.
  • ChatMessage.from_dict and StreamingChunk.from_dict are untouched: they hand-build their fields and already use
    cls, so they never had this problem.

Checklist


AI assistance: this patch and its tests were drafted with an AI assistant under my direction. I reviewed the diff and ran the relevant tests locally — without the change the new cases fail (5 failed, 1 passed); with it the file is green (203 passed).

This PR was prepared with an AI assistant (Hermes); I reviewed the diff and ran the tests.

@simin-yuan
simin-yuan requested a review from a team as a code owner November 6, 2026 17:28
@simin-yuan
simin-yuan requested review from davidsbatista and removed request for a team November 6, 2026 17:28
@vercel

vercel Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@simin-yuan is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

ToolCall, ToolCallResult, ReasoningContent, ToolCallDelta and ComponentInfo
hardcoded their own class in from_dict, so a subclass lost its extra fields on
a to_dict()/from_dict() round trip. deepset-ai#13180 and deepset-ai#13536 fixed the same bug for
ByteStream and for TextContent/FileContent/ImageContent; this completes the set
in haystack/dataclasses.

Signed-off-by: Simin Yuan <281164480+simin-yuan@users.noreply.github.com>
@simin-yuan
simin-yuan force-pushed the fix/content-part-from-dict-subclasses branch from 03ebf83 to c20aac5 Compare November 6, 2026 17:31
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/core/pipeline
  pipeline.py
  haystack/dataclasses
  chat_message.py
  streaming_chunk.py
Project Total  

This report was generated by python-coverage-comment-action

@simin-yuan

Copy link
Copy Markdown
Contributor Author

Closing this as I'm not able to follow up on it. Thanks for the time.

@simin-yuan simin-yuan closed this Nov 13, 2026
@simin-yuan simin-yuan reopened this Nov 19, 2026
@github-actions github-actions Bot added the type:documentation Improvements on the docs label Nov 19, 2026
@simin-yuan

Copy link
Copy Markdown
Contributor Author

Merged current main into the branch; tests pass. The issue is still present on main (ToolCall.from_dict still returns the base class for subclasses). Happy to adjust.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant