fix: give each FileContent its own extra dict in FileToFileContent#11872
Open
Vedant-Agarwal wants to merge 1 commit into
Open
fix: give each FileContent its own extra dict in FileToFileContent#11872Vedant-Agarwal wants to merge 1 commit into
Vedant-Agarwal wants to merge 1 commit into
Conversation
normalize_metadata returns the same dict object for every source when extra is a single dict (or None). FileToFileContent passed that shared object straight into each FileContent, so mutating one file's extra downstream leaked into all the others. Copy the dict per source, matching the other converters which merge extra into a fresh dict. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@Vedant-Agarwal is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
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:
FileToFileContent.run()normalizesextravianormalize_metadata(), which returns[meta] * sources_countfor a single dict and[{}] * sources_countforNone— i.e. the same dict object repeated. The component then passed that object straight into everyFileContent(..., extra=extra_dict), so allFileContents produced by onerun()share oneextradict. Mutating one file'sextradownstream (e.g.files[0].extra["page"] = 1) silently mutates every sibling'sextra.FileToFileContentis the only converter affected: the text/pdf/docx/tika/csv/markdown converters consumenormalize_metadata()but merge into a fresh{**bytestream.meta, **metadata}dict per source, so the shared return is harmless for them.The fix copies the dict per source (
extra=dict(extra_dict)), matching the other converters' behaviour.How did you test it?
test_run_with_extra_dict_does_not_share_reference, which asserts the twoFileContents don't alias the sameextraand that mutating one doesn't leak into the other. It fails onmain({'tenant': 'acme'} is not {'tenant': 'acme'}→ AssertionError) and passes with the fix.python -m pytest test/components/converters/test_file_to_file_content.py→ all green.ruff check/ruff format --checkclean on both files.Notes for the reviewer
Minimal one-line change at the sink. I considered fixing
normalize_metadata()to return independent dicts, but scoped it to the only broken consumer to avoid changing a shared utility that every other converter already handles safely.This PR was written with the help of an AI assistant. I have reviewed the changes and run the relevant tests locally.
Checklist
fix:).