Skip to content

fix: give each FileContent its own extra dict in FileToFileContent#11872

Open
Vedant-Agarwal wants to merge 1 commit into
deepset-ai:mainfrom
Vedant-Agarwal:fix/file-to-file-content-shared-extra
Open

fix: give each FileContent its own extra dict in FileToFileContent#11872
Vedant-Agarwal wants to merge 1 commit into
deepset-ai:mainfrom
Vedant-Agarwal:fix/file-to-file-content-shared-extra

Conversation

@Vedant-Agarwal

Copy link
Copy Markdown

Related Issues

  • N/A — small self-contained bug fix found while reading the converters.

Proposed Changes:

FileToFileContent.run() normalizes extra via normalize_metadata(), which returns [meta] * sources_count for a single dict and [{}] * sources_count for None — i.e. the same dict object repeated. The component then passed that object straight into every FileContent(..., extra=extra_dict), so all FileContents produced by one run() share one extra dict. Mutating one file's extra downstream (e.g. files[0].extra["page"] = 1) silently mutates every sibling's extra.

FileToFileContent is the only converter affected: the text/pdf/docx/tika/csv/markdown converters consume normalize_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?

  • Added test_run_with_extra_dict_does_not_share_reference, which asserts the two FileContents don't alias the same extra and that mutating one doesn't leak into the other. It fails on main ({'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 --check clean 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

  • I have read the contributors guidelines and the code of conduct.
  • I've used a conventional commit type for the PR title (fix:).
  • I have added unit tests and documented my code.
  • I have added a release note file.

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 Vedant-Agarwal requested a review from a team as a code owner July 5, 2026 13:03
@Vedant-Agarwal Vedant-Agarwal requested review from bogdankostic and removed request for a team July 5, 2026 13:03
@vercel

vercel Bot commented Jul 5, 2026

Copy link
Copy Markdown

@Vedant-Agarwal is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Jul 5, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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