fix: prevent GeneratedAnswer.from_dict crash on empty all_messages#11626
Merged
davidsbatista merged 5 commits intoJun 16, 2026
Merged
Conversation
|
@i-anubhav-anand is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
GeneratedAnswer.from_dict guarded meta['all_messages'] with 'is not None', so an empty list passed the check and the subsequent all_messages[0] access raised IndexError. to_dict already uses a truthiness guard; align from_dict with it so an empty all_messages list round-trips instead of crashing.
32a814c to
f983755
Compare
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
davidsbatista
approved these changes
Jun 16, 2026
davidsbatista
left a comment
Contributor
There was a problem hiding this comment.
Looks good! Thanks @i-anubhav-anand for the contribution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
Self-found bug (no existing issue).
GeneratedAnswer.from_dictcrashes withIndexErrorwhen the serializedmetacontains an emptyall_messageslist — whichto_dictitself can emit, so a plain round-trip crashes.Proposed Changes:
GeneratedAnswer.from_dictguarded the metadata branch withis not None:An empty list
[]isnot None, so it passes the guard and the immediateall_messages[0]access raisesIndexError: list index out of range.to_dictalready uses the correct truthiness guard (if all_messages and isinstance(all_messages[0], ChatMessage)), which leaves an emptyall_messagesuntouched in the output — soto_dict→from_dictround-trips into the crash.The fix aligns
from_dictwithto_dictby using the same truthiness guard, so an emptyall_messageslist round-trips correctly instead of crashing.Reproduction (before the fix):
How did you test it?
Added two unit tests in
test/dataclasses/test_answer.py:test_from_dict_with_empty_all_messages— deserializingmeta={"all_messages": []}no longer raises.test_to_dict_from_dict_round_trip_with_empty_all_messages— full round-trip equality.Both fail on
main(IndexError) and pass with this change. Ranhatch run test:unit test/dataclasses/test_answer.py(20 passed),hatch run fmt(clean), andhatch run test:types haystack/dataclasses/answer.py(mypy clean). Added a release note underreleasenotes/notes.Notes for the reviewer
One-line behavior fix; the existing non-empty /
ChatMessage/ stringall_messagespaths are unchanged and still covered by the existing tests.Checklist
fix:).hatch run fmtand fixed any issue.