Skip to content

fix(generators): serialize timeout and max_retries in OpenAIImageGenerator.to_dict - #12290

Draft
Anai-Guo wants to merge 1 commit into
deepset-ai:mainfrom
Anai-Guo:fix-image-generator-serialize-client-settings
Draft

fix(generators): serialize timeout and max_retries in OpenAIImageGenerator.to_dict#12290
Anai-Guo wants to merge 1 commit into
deepset-ai:mainfrom
Anai-Guo:fix-image-generator-serialize-client-settings

Conversation

@Anai-Guo

Copy link
Copy Markdown

Related Issues

  • No open issue; found while auditing to_dict() coverage across components.

Proposed Changes:

OpenAIImageGenerator.__init__ takes timeout and max_retries, stores both on the instance, and _client_kwargs() passes them to OpenAI/AsyncOpenAI. to_dict() never emitted them, so they were lost on the way through a serialized pipeline:

g = OpenAIImageGenerator(timeout=60.0, max_retries=10)
g2 = OpenAIImageGenerator.from_dict(g.to_dict())

g._client_kwargs()   # {'timeout': 60.0, 'max_retries': 10}
g2._client_kwargs()  # {'timeout': 30.0, 'max_retries': 5}   <- silently back to the defaults

The fallback is silent: _client_kwargs() reads OPENAI_TIMEOUT/OPENAI_MAX_RETRIES or defaults to 30s / 5 retries whenever the attribute is None, so a deserialized pipeline just runs with different client settings than the one that was saved.

This is the only OpenAI-backed component with the gap — OpenAIChatGenerator, OpenAIGenerator, AzureOpenAIChatGenerator, AzureOpenAIResponsesChatGenerator, OpenAIResponsesChatGenerator, OpenAI{Text,Document}Embedder, AzureOpenAI{Text,Document}Embedder and OpenAITokenCounter all serialize both fields already.

response_format is deliberately left out: it is documented as ignored and only kept for backward compatibility, and __init__ warns when it is set to anything other than "b64_json".

How did you test it?

hatch run test:unit -k openai_image_generator equivalent (pytest test/components/generators/test_openai_image_generator.py):

  • before the fix: 3 failed, 20 passed, 2 skipped — the two updated to_dict expectations plus the new round-trip test
  • after the fix: 23 passed, 2 skipped

Updated test_to_dict, test_to_dict_with_params and test_from_dict to cover the two fields (test_to_dict_with_params already passed timeout=60, max_retries=10 into the constructor but asserted they were dropped), and added test_to_dict_from_dict_roundtrip_keeps_client_kwargs, which asserts _client_kwargs() is identical across a to_dict()/from_dict() round trip.

ruff check and ruff format --check are clean on both touched files.

Notes for the reviewer

The branch is cut from an older main because my fork cannot be fast-forwarded (my token has no workflow scope and syncing touches .github/workflows/). The three hunks are pure additions and merge cleanly onto current main; happy to rebase if you prefer.

Checklist


This PR was written with an AI assistant (Claude Code). I have reviewed the changes and run the relevant tests locally.

🤖 Generated with Claude Code

@Anai-Guo
Anai-Guo requested a review from a team as a code owner August 10, 2026 13:21
@Anai-Guo
Anai-Guo requested review from julian-risch and removed request for a team August 10, 2026 13:21
@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown

@Anai-Guo is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

…rator.to_dict

`OpenAIImageGenerator.__init__` accepts `timeout` and `max_retries` and
`_client_kwargs()` uses both when building the OpenAI client, but
`to_dict()` never emitted them. A pipeline that is serialized and loaded
back therefore silently falls back to `OPENAI_TIMEOUT`/`OPENAI_MAX_RETRIES`
or to the 30s / 5 retries defaults.

Every other OpenAI-backed component already serializes them
(`OpenAIChatGenerator`, `OpenAIGenerator`, the Azure chat generators, the
OpenAI/Azure embedders, `OpenAITokenCounter`); this one was the only
outlier.

`response_format` stays out on purpose - it is documented as ignored and
kept only for backward compatibility.
@Anai-Guo
Anai-Guo force-pushed the fix-image-generator-serialize-client-settings branch from 13b94c7 to d62a307 Compare August 10, 2026 13:24
@julian-risch

Copy link
Copy Markdown
Member

The changes look good to me @Anai-Guo ! Thank you for opening this PR. As soon as you agree to the CLA we can merge this PR.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @Anai-Guo, 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 added the cla-pending PR is in draft until the contributor signs the CLA label Aug 10, 2026
@HaystackBot
HaystackBot marked this pull request as draft August 10, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-pending PR is in draft until the contributor signs the CLA topic:tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants