Skip to content

fix: let Pipeline.connect match Union and Literal members in any order - #13510

Merged
sjrl merged 1 commit into
deepset-ai:mainfrom
Revinand:fix/union-sender-type-compatibility
Nov 6, 2026
Merged

sjrl merged 1 commit into
deepset-ai:mainfrom
Revinand:fix/union-sender-type-compatibility

Conversation

@Revinand

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

_strict_types_are_compatible compared the members of two Union types, and the values of two Literal types, by position. A connection passed only when each sender member matched the receiver member at the same position: str | None connected to str | None | int, but not to str | int | None.

A Union sender is now compatible when each of its members is compatible with the receiving Union, which reuses the existing branch for a non-union sender. A Literal sender is compatible when all of its values are in the receiving Literal. A release note describes the change.

How did you test it?

New cases in test/core/test_type_utils.py:

  • compatible: Literal["b", "c"] to Literal["a", "b", "c"], Optional[str] to Union[int, str, None], str | None to str | int | None, and list[Path | ByteStream] to list[str | Path | ByteStream]. All four fail on main. The existing reverse-direction test checks each of them the other way round, where they stay incompatible.
  • incompatible: Literal["a", "x"] to Literal["a", "b", "c"]. It fails if the Literal check accepts a sender with only some of its values in the receiver; the existing partially overlapping union cases do the same for the Union check.

test/core passes (1893 passed), except test_show_in_notebook, which needs IPython, not installed in my environment. It fails the same way on main. mypy on type_utils.py and the pre-commit hooks pass.

Notes for the reviewer

One existing case changes. test_partially_overlapping_unions_are_not_compatible_strict used int | bool to int | str. bool is a subclass of int, and the same file treats bool to int as compatible (different-primitives), which makes every member of int | bool fit int | str once members are checked one by one. I replaced bool with float in both spellings to keep the partial overlap.

FileTypeRouter declares list[str | Path | ByteStream] outputs to work around this bug. With this fix it could declare list[Path | ByteStream]; I left that out to keep this PR to the type check.

This PR was fully generated with an AI assistant. I have reviewed the changes and run the relevant tests.

Checklist

@Revinand
Revinand requested a review from a team as a code owner October 31, 2026 18:37
@Revinand
Revinand requested review from julian-risch and removed request for a team October 31, 2026 18:37
@vercel

vercel Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

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

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/core
  type_utils.py
Project Total  

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

@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sjrl sjrl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@sjrl
sjrl removed the request for review from julian-risch November 6, 2026 13:25
@sjrl sjrl self-assigned this Nov 6, 2026
@sjrl
sjrl merged commit ddcde93 into deepset-ai:main Nov 6, 2026
28 of 29 checks passed
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.

Pipeline.connect rejects Union and Literal types whose members are in a different order

3 participants