Skip to content

fix(tools): keep dataclass default factories lazy - #13690

Open
Elon-Jiang wants to merge 1 commit into
deepset-ai:mainfrom
Elon-Jiang:fix/tools-dataclass-factories-20261111
Open

Elon-Jiang wants to merge 1 commit into
deepset-ai:mainfrom
Elon-Jiang:fix/tools-dataclass-factories-20261111

Conversation

@Elon-Jiang

Copy link
Copy Markdown

Related Issues

Fixes #13689.

Proposed Changes:

ComponentTool executes dataclass default_factory functions while constructing parameter schemas. A counting factory is called once before any invocation, so the first real invocation receives the second generated value. A factory that depends on an unavailable runtime resource prevents tool construction even when the caller would supply the field explicitly.

Preserve the callable as a Pydantic Field(default_factory=...) instead of executing it during schema conversion. Factory-backed fields stay optional and no longer advertise a captured concrete default; explicit static defaults are unchanged. Update the existing schema expectations, public documentation and release note to describe this visible schema change.

How did you test it?

Python 3.12.13, Hatch 1.18.2, Haystack 3.6.0-rc0, baseline 3a753721265dc167bc908b947d7d33e7fead76f5:

  • Standalone public ComponentTool reproduction: baseline constructs with one factory call and returns token 2 on first invocation; patched construction makes zero calls and first invocation returns token 1. Providing an explicit token does not run the factory.
  • Original source: three new regressions fail, two existing dataclass controls pass. New tests cover sync and async invocation, fresh values on repeated calls, optional schema fields, explicit-value bypass and a factory that raises if invoked during setup.
  • hatch run test:unit test/tools test/core/test_type_utils.py test/core/component test/components/agents -q --no-cov: 1828 passed, 2 skipped, 18 deselected (3 warnings).
  • hatch run test:types on the four changed Python files: no issues.
  • hatch run fmt and all applicable pre-commit run --files ... hooks passed, including Ruff, codespell, release-note checks and syntax/YAML checks.
  • hatch build -t wheel passed; git diff --check passed.

Tests execute actual dataclass construction, schema generation and public tool invocation; no external model, service or replacement implementation is involved. Live-provider integration tests and the entire documentation website build were not run.

Notes for the reviewer

The nearby #13516 fixes postponed dataclass annotations and leaves the eager factory call in place; it addresses a separate defect. This patch keeps the change local to default handling and can be rebased if that annotation change lands first.

This PR was fully generated with OpenAI Codex. Codex reviewed the diff and ran the recorded checks; this does not assert personal code review or testing by the account owner.

Checklist

  • Read the contribution guidelines and code of conduct.
  • Linked the reproduced bug and supplied its context.
  • Added unit tests and updated the docstrings.
  • Used a conventional commit title.
  • Updated public documentation.
  • Added a release note with the visible schema change and upgrade guidance.
  • Ran the applicable pre-commit hooks.

@Elon-Jiang
Elon-Jiang requested a review from a team as a code owner November 11, 2026 12:59
@Elon-Jiang
Elon-Jiang requested review from bogdankostic and removed request for a team November 11, 2026 12:59
@vercel

vercel Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

@Elon-Jiang is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Nov 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @Elon-Jiang, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot removed the request for review from bogdankostic November 11, 2026 14:22
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Nov 11, 2026
@HaystackBot
HaystackBot marked this pull request as draft November 11, 2026 14:22
@HaystackBot
HaystackBot marked this pull request as ready for review November 12, 2026 02:07
@HaystackBot HaystackBot removed the cla-pending PR is in draft until the contributor signs the CLA label Nov 12, 2026
@HaystackBot

Copy link
Copy Markdown
Contributor

Thanks for signing the CLA, @Elon-Jiang! 🎉 This PR is now ready for review again and the reviewer has been re-assigned.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ComponentTool executes dataclass default factories during schema generation

3 participants