Repository navigation
Conversation
Tool.from_dict(), ComponentTool.from_dict(), PipelineTool.from_dict() and AgentTool.from_dict() rewrote the caller's dictionary in place, replacing serialized callables and the serialized component/agent/pipeline with live objects. After one deserialization the original configuration no longer held serialized data, and loading the same dictionary a second time crashed with AttributeError inside deserialize_callable(). Deserialize a copy instead, mirroring what BranchJoiner.from_dict() and MockChatGenerator.from_dict() already do, so the same dictionary can be loaded more than once and stays serializable. Signed-off-by: simpleqt <2015900818@qq.com>
Contributor
|
@simpleqt 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 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
|
Thanks for the PR! In general |
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.
Related Issues
from_dict()mutating the caller's serialized configuration.Proposed Changes:
Tool.from_dict(),ComponentTool.from_dict(),PipelineTool.from_dict(), andAgentTool.from_dict()deserialized in place, writing the result back into the dictionary supplied by the caller:Tool.from_dict()replaceddata["data"]["function"]/["async_function"]with the resolved callables and rewrotedata["data"]["outputs_to_state"]/["outputs_to_string"]handlers with live callables.ComponentTool.from_dict()/AgentTool.from_dict()replaceddata["data"]["component"]/["agent"]with the live component instance, andPipelineTool.from_dict()poppedis_pipeline_asyncand rewrote theoutputs_to_*configs inside the caller's dict.Consequences of one
from_dict()call on a user-held dictionary:json.dumps/yaml.dumpand no longer compares equal totool.to_dict();from_dict()on the same dictionary a second time crashes withAttributeError: 'function' object has no attribute 'split'insidedeserialize_callable()— this also hitsToolset.from_dict()anddeserialize_tools_or_toolset_inplace(), which pass their nested tool dictionaries straight toTool.from_dict().The fix deserializes a copy instead (shallow copy of the tool parameters;
deepcopyof the nested serialized component/agent, because the nested component's ownfrom_dict()also rewrites itsinit_parametersin place), so the caller's dictionary keeps the serialized configuration and can be loaded more than once. This mirrors whatBranchJoiner.from_dict()("Copy so the caller's data keeps the serialized type and can be deserialized again") and the mergedMockChatGenerator.from_dict()fix (#13471) already do.The
parameters=inner_data.get("parameters", None)→get("parameters")adjustments inComponentTool.from_dictareruff --fix(SIM910) output: the copied dict is now statically adict, which newly triggers the rule on those lines.How did you test it?
from_dict(data)the input still equals its deep-copied snapshot and that a secondfrom_dict(data)succeeds:test/tools/test_tool.py::TestToolAsync::test_from_dict_preserves_inputtest/tools/test_component_tool.py::TestComponentToolInAgent::test_from_dict_preserves_inputtest/tools/test_pipeline_tool.py::TestPipelineTool::test_from_dict_preserves_inputtest/tools/test_agent_tool.py::TestAgentTool::test_from_dict_preserves_input4 failed in 1.68s, failing atassert data == snapshot); with the fix, all 4 pass (4 passed in 1.05s).pytest test/tools/ test/components/agents/: 661 passed, 18 skipped (pre-existing optional-dependency skips).test/core test/components test/utils test/tools, minus files needing heavy optional deps not installed locally): 5405 passed / 230 failed / 150 skipped with the fix vs 5400 passed / 231 failed on cleanmain. The failure sets are identical except one flaky async cancellation test (test_async_pipeline_stream.py::test_consumer_cancellation_cancels_pipeline) that failed only in themainrun; all failures come from missing optional deps (torch, tiktoken, pillow, pypdf, jq, ...) and network-dependent fetcher tests on this machine. Zero tests newly fail with this change.ruff checkandruff format --check(pinned v0.16.0) pass on all changed files.Notes for the reviewer
Pipeline.from_dict()was already safe (it deep-copies the payload in_from_dict_impl); this PR fixes the directTool/Toolset/component-tool paths, which had no such protection.init_parameterscan still be rewritten by that component's ownfrom_dict()(a repo-wide pattern). This PR scopes the copy to what the tool classes themselves deserialize, so components with in-placefrom_dict()implementations (e.g.OpenAIChatGenerator) can be migrated opportunistically later, as was done forMockChatGeneratorandBranchJoiner.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.This PR was fully generated with an AI assistant. I have reviewed the changes and run the relevant tests.
AI-assistance disclosure: this change and this description were prepared by an AI coding agent (DeepSeek Harness, model dsv41) working under the direction of the submitter, who reviewed the diff and the evidence before opening the pull request and takes responsibility for it.