fix: avoid in-place mutation of ExtractedAnswer in ExtractiveReader#11296
Merged
Conversation
fix: avoid in-place mutation of ExtractedAnswer in ExtractiveReader
Replace `answer.meta = {}` with `dataclasses.replace(answer, meta={})` in
`_add_answer_page_number` to avoid triggering the dataclass mutation
warning when an incoming answer has `meta=None`.
Follow-up to epic deepset-ai#10564; fills a site missed by the sweep in deepset-ai#10659
(which listed line 393 but not line 323).
@
|
@HamidOna13 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
sjrl
reviewed
May 12, 2026
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
Proposed Changes
ExtractiveReader._add_answer_page_numberdidanswer.meta = {}when theincoming answer had
meta=None. That triggers the in-place mutation warningadded in #10650. Replaced with
dataclasses.replace(answer, meta={}).The earlier sweep in #10659 caught
extractive.py:393but missed line 323,so this fills that gap.
How did you test it?
Added
test_add_answer_page_number_with_none_metawhich calls the methodwith
meta=Noneinsidewarnings.simplefilter("error"), so any mutationwarning fails the test. Also ran
hatch run test:unit test/components/readers/test_extractive.pylocally.
Notes for the reviewer
While looking around I noticed a few sites that mutate dict contents on
input parameters (e.g.
doc.meta["x"] = y). The current warning only catchesattribute reassignment, so these don't fire it:
haystack/components/preprocessors/hierarchical_document_splitter.py:78mutates
document.metaon an inputDocumenthaystack/components/generators/chat/hugging_face_api.py:617,688mutates
message.meta["usage"]on an inputChatMessagehaystack/components/audio/whisper_remote.py:155mutatessource.meta(This one is probably fine since
sourceis constructed two lines above but just mentioning it)Not sure if dict-content mutations are in scope for #10564. Happy to open
follow-up PRs if any of these are worth fixing.
Checklist
fix:)