fix: serialize nested chat generators via component_to_dict in FallbackChatGenerator - #11847
Conversation
|
@rautaditya2606 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Fixes FallbackChatGenerator nested-component serialization so custom chat generators that rely on Haystack’s default constructor-based SerDe are no longer silently dropped during to_dict() / from_dict() round-trips.
Changes:
- Updated
FallbackChatGenerator.to_dict()to serialize nested generators viacomponent_to_dict()(instead of filtering onhasattr(..., "to_dict")). - Added unit tests covering mixed fallback chains, order preservation, round-trip execution, and fail-loud behavior for non-serializable components.
- Added a release note documenting the serialization fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
haystack/components/generators/chat/fallback.py |
Uses component_to_dict() for nested generator serialization, preventing silent omission of otherwise-serializable components. |
test/components/generators/chat/test_fallback.py |
Adds regression tests for serialization/deserialization correctness and explicit failure on non-serializable init parameters. |
releasenotes/notes/fix_fallback_chat_generator_serialization-9498ee2bbe2971be.yaml |
Documents the behavioral fix in release notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
|
|
||
|
|
||
| def test_serialization_with_custom_generators_without_to_dict(): | ||
| from haystack.core.errors import SerializationError |
There was a problem hiding this comment.
Please move the import to the top of the file
There was a problem hiding this comment.
done, i've moved the import to the top of the file
thanks
sjrl
left a comment
There was a problem hiding this comment.
Looks good! Thanks for the contribution!
Summary
Fixes #11846.
Proposed Changes
FallbackChatGenerator.to_dict()inhaystack/components/generators/chat/fallback.pyto usecomponent_to_dict()instead of directly calling.to_dict()on nested chat generators.test_fallback.pycovering:to_dict()methods),How did you test it?
Result:
Notes for the reviewer
Root cause
FallbackChatGeneratorserialized its nested chat generators using:This bypassed Haystack's standard serialization helper (
component_to_dict()), which supports components that do not implement explicitto_dict()/from_dict()methods by falling back to constructor-based serialization. As a result, otherwise serializable components were silently omitted from the serialized representation.Reproducer
Precedent
This change follows the same serialization pattern already used by
Agent.to_dict(), which serializes nested components throughcomponent_to_dict().Checklist
releasenotes/notes/fix_fallback_chat_generator_serialization-9498ee2bbe2971be.yaml)