Skip to content

fix: updating generated answer and extracted answers serialisation#11805

Merged
davidsbatista merged 6 commits into
mainfrom
fix/updating-GeneratedAnswer-and-ExtractedAnswers-serialisation
Jun 30, 2026
Merged

fix: updating generated answer and extracted answers serialisation#11805
davidsbatista merged 6 commits into
mainfrom
fix/updating-GeneratedAnswer-and-ExtractedAnswers-serialisation

Conversation

@davidsbatista

@davidsbatista davidsbatista commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

  • GeneratedAnswer and ExtractedAnswer were serializing via default_to_dict / default_from_dict
  • Every other dataclass (Document, ChatMessage, etc.) produces a flat, field-keyed dict from to_dict().
  • This PR aligns both classes with the flat pattern

How did you test it?

  • Updated unit tests to reflect the new flat format; the old-format tests were renamed _legacy and kept to verify backward compatibility.
  • New test_from_dict tests were added for both GeneratedAnswer and ExtractedAnswer

Notes for the reviewer

  • from_dict() still accepts the old format (e.g. from a saved pipeline snapshot), it unwraps init_parameters before processing.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
haystack-docs Ignored Ignored Preview Jun 30, 2026 3:37pm

Request Review

@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/dataclasses
  answer.py
Project Total  

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

@davidsbatista davidsbatista marked this pull request as ready for review June 29, 2026 10:58
@davidsbatista davidsbatista requested a review from a team as a code owner June 29, 2026 10:58
@davidsbatista davidsbatista requested review from julian-risch and removed request for a team June 29, 2026 10:58
@claude

claude Bot commented Jun 29, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@davidsbatista davidsbatista changed the title Fix/updating generated answer and extracted answers serialisation fix: updating generated answer and extracted answers serialisation Jun 30, 2026
Copy the meta dict before reassigning all_messages so deserialization
no longer mutates the caller's input. Matches the no-mutation behavior
of ExtractedAnswer.from_dict and Document.from_dict. Adds a regression
test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@julian-risch julian-risch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me now. I pushed a small change myself. The serialization/deserialization roundtrip of GenerateAnswer was broken in the sense that it mutated meta. That was an issue before in GeneratedAnswer and in ExtractedAnswer. Your changes fixed it for ExtractedAnswer and so pushed a small change to achieve consistency.
Regarding the corresponding issue: Let's not close it directly. I would like us to align with @anakin87 and @sjrl if there are really no serialization changes we want to roll out with Haystack 3.0.

@davidsbatista davidsbatista merged commit e40103f into main Jun 30, 2026
27 checks passed
@davidsbatista davidsbatista deleted the fix/updating-GeneratedAnswer-and-ExtractedAnswers-serialisation branch June 30, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants