fix: rebuild namedtuples in _deepcopy_with_exceptions#11981
Open
chuenchen309 wants to merge 1 commit into
Open
fix: rebuild namedtuples in _deepcopy_with_exceptions#11981chuenchen309 wants to merge 1 commit into
chuenchen309 wants to merge 1 commit into
Conversation
_deepcopy_with_exceptions rebuilt list/tuple/set values with type(obj)(<generator>), but a namedtuple's __new__ takes its fields positionally, not as a single iterable. Copying a component input or parameter that held a namedtuple therefore raised TypeError, defeating the function's graceful-fallback contract. Rebuild namedtuples by unpacking their deep-copied fields. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@chuenchen309 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
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.
What
_deepcopy_with_exceptions(used when Haystack copies component inputs/params) is designed to degrade gracefully: if an object cannot be deep-copied it returns the original and logs. But its container branch crashes on anamedtuple:A
namedtupleis atuplesubclass, so it takes this branch — buttype(obj)(<generator>)calls the namedtuple's__new__with a single iterable, whereas its__new__expects the fields as positional arguments. The result is an uncaughtTypeError, which propagates out of the copy (also through any dict/list that contains the namedtuple), defeating the function's own graceful-fallback contract.Reproduction:
Fix
Handle namedtuples explicitly (detected via the
_fieldsattribute) before the generic list/tuple/set branch, rebuilding them by unpacking their deep-copied fields. Plain tuples/lists/sets are unaffected.Test
Added
TestDeepcopyWithFallback::test_deepcopy_with_fallback_namedtuple, which fails before the change (theTypeErrorabove) and passes after, verifying the namedtuple is reconstructed as its own type with deep-copied contents.Verified locally: the full
test/core/pipeline/test_utils.pysuite passes (27 passed).ruff checkandruff format --checkare clean. Added a release note.Authored with AI assistance (Claude Code); the change and tests were reviewed and verified locally by me.