Skip to content

fix: preserve ByteStream subclasses during deserialization - #13180

Open
JimmyWang0417 wants to merge 1 commit into
deepset-ai:mainfrom
JimmyWang0417:JimmyWang0417/fix-bytestream-subclass-deserialization
Open

JimmyWang0417 wants to merge 1 commit into
deepset-ai:mainfrom
JimmyWang0417:JimmyWang0417/fix-bytestream-subclass-deserialization

Conversation

@JimmyWang0417

Copy link
Copy Markdown
Contributor

Related Issues

No existing issue. Reproduced through a subclass serialization round trip.

Proposed Changes

CustomByteStream.from_dict(original.to_dict()) currently returns a ByteStream, even when original is a CustomByteStream. Use cls to construct the result, matching from_string() and from_file_path().

Add a subclass round-trip regression test, clarify the return-value docstring, and include a release note.

How did you test it?

Checks ran through Hatch with Python 3.12. The default environment had the temporary test/type-check dependencies installed; the full optional integration dependency set was not installed.

  • The new regression test fails against the original implementation.
  • hatch -e default run python -m pytest test/dataclasses/test_byte_stream.py -q: 37 passed.
  • hatch -e default run fmt-check haystack/dataclasses/byte_stream.py test/dataclasses/test_byte_stream.py: passed.
  • hatch -e default run mypy --follow-imports=silent haystack/dataclasses/byte_stream.py test/dataclasses/test_byte_stream.py: passed.
  • Pre-commit checks for all three changed files and git diff --check: passed.

Notes for the reviewer

The serialized fields and defaults are unchanged. This PR was fully generated with an AI assistant. The assistant reviewed the complete diff and ran the checks listed above.

Checklist

  • Read the contributor guidelines and code of conduct.
  • Added a regression test and updated the return-value docstring.
  • Used a conventional commit title.
  • Added a Reno release note.
  • Ran pre-commit checks on the changed files.
  • Related-issue update: not applicable.

@JimmyWang0417
JimmyWang0417 requested a review from a team as a code owner October 8, 2026 12:48
@JimmyWang0417
JimmyWang0417 requested review from bogdankostic and removed request for a team October 8, 2026 12:48
@vercel

vercel Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

@JimmyWang0417 is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

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

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

@0xamlab

0xamlab commented Oct 8, 2026

Copy link
Copy Markdown

Confirmed the bug on current main: CustomByteStream.from_dict(d) returns a plain ByteStream, so subclass identity is lost. The cause is haystack/dataclasses/byte_stream.py:124 hardcoding ByteStream(...) instead of using cls(...). Checked out this PR and the round-trip now preserves the subclass. Ran test/dataclasses/test_byte_stream.py — 37 passed, including the new test_from_dict_preserves_subclass. Also ran the broader test/dataclasses/ slice (319 passed; 3 unrelated failures from missing optional deps for Jupyter image display and async callbacks) and both ruff and mypy are clean on the changed files. LGTM.

@JimmyWang0417

Copy link
Copy Markdown
Contributor Author

Confirmed the bug on current main: CustomByteStream.from_dict(d) returns a plain ByteStream, so subclass identity is lost. The cause is haystack/dataclasses/byte_stream.py:124 hardcoding ByteStream(...) instead of using cls(...). Checked out this PR and the round-trip now preserves the subclass. Ran test/dataclasses/test_byte_stream.py — 37 passed, including the new test_from_dict_preserves_subclass. Also ran the broader test/dataclasses/ slice (319 passed; 3 unrelated failures from missing optional deps for Jupyter image display and async callbacks) and both ruff and mypy are clean on the changed files. LGTM.

Thanks for independently reproducing this and running the broader checks! I appreciate the extra validation of the subclass round-trip.

@0xamlab

0xamlab commented Oct 9, 2026

Copy link
Copy Markdown

You're welcome — the subclass round-trip was the case worth pinning down, and the cls(...) fix is the right shape. Nice work.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants