haystack icon indicating copy to clipboard operation
haystack copied to clipboard

fix: SuperComponent input filter must use identity, not equality

Open Aarkin7 opened this issue 5 months ago • 8 comments

Proposed Changes:

SuperComponent.run and SuperComponent.run_async filtered out the internal _delegate_default sentinel with value != _delegate_default. That calls __ne__ on every user-provided input, which for numpy arrays, pandas DataFrames/Series, and torch tensors returns an element-wise array, and the dict-comprehension's boolean context then raises ValueError: The truth value of ... is ambiguous. So passing any array-shaped input (a routine ML pipeline thing) failed before the wrapped pipeline ever ran.

Switched both call sites to is not _delegate_default. That's an identity check on a sentinel class — what the filter actually meant, and it never touches __ne__ on user values.

How did you test it?

  • Added two unit tests in TestSuperComponentDelegateDefaultFiltering covering the sync (run) and async (run_async) paths with a real numpy.ndarray input.
  • hatch run test:unit test/core/super_component/, all 29 tests pass (27 pre-existing + 2 new).
  • hatch run test:unit test/core/, 1587 passed, no regressions.
  • hatch run test:types haystack/core/super_component/super_component.py: clean.
  • hatch run fmt-check: clean.

Notes for the reviewer

  • Two-line behavioural change, repeated in run (line 122) and run_async (line 150). I kept a one-line # is not, not != comment above each so the next reader doesn't "simplify" it back.
  • Semantic equivalence for ordinary values: _delegate_default is a class object with no __eq__ override, so for any value that doesn't overload __ne__, != and is not produce the same result. Behaviour changes only for (a) array-like values that overload __ne__ to return non-scalar (the fix), and (b) the pathological case of a user class whose __eq__ returns True for everything (previously silently dropped, now correctly kept, strict improvement).
  • Release note added under releasenotes/notes/.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

Aarkin7 avatar Jun 14 '26 18:06 Aarkin7

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

A member of the Team first needs to authorize it.

vercel[bot] avatar Jun 14 '26 18:06 vercel[bot]

@bogdankostic for some additional context we did run into a problem like this before in our Pipeline class here https://github.com/deepset-ai/haystack/pull/8873

sjrl avatar Jun 15 '26 05:06 sjrl

@bogdankostic I can take over the review for this

sjrl avatar Jun 18 '26 07:06 sjrl

Hey @Aarkin7 soft ping to address this comment https://github.com/deepset-ai/haystack/pull/11624#discussion_r3433784366

sjrl avatar Jun 19 '26 06:06 sjrl

Hey @Aarkin7 do you have time to work on this in the near future?

sjrl avatar Jun 24 '26 07:06 sjrl

Hi @sjrl I'll look into it

Aarkin7 avatar Jun 24 '26 08:06 Aarkin7

Coverage report

Click to see where and how coverage changed

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

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

github-actions[bot] avatar Jun 24 '26 13:06 github-actions[bot]

Hi @sjrl , Thanks! Moved numpy to a normal top-level import and removed the importorskip from both tests.

Aarkin7 avatar Jun 24 '26 14:06 Aarkin7