Skip to content

fix: serialize timeout and max_retries in OpenAIImageGenerator.to_dict - #12518

Open
pcbeingused333 wants to merge 2 commits into
deepset-ai:mainfrom
pcbeingused333:fix/openai-image-generator-serialize-timeout-max-retries
Open

fix: serialize timeout and max_retries in OpenAIImageGenerator.to_dict#12518
pcbeingused333 wants to merge 2 commits into
deepset-ai:mainfrom
pcbeingused333:fix/openai-image-generator-serialize-timeout-max-retries

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

OpenAIImageGenerator.__init__ accepts timeout and max_retries, stores them, and _client_kwargs() uses them to build the OpenAI client — but to_dict didn't include them, so they were dropped on serialization and reverted to the OPENAI_TIMEOUT / OPENAI_MAX_RETRIES fallbacks (30s, 5) on load:

original = OpenAIImageGenerator(timeout=120.0, max_retries=10)
restored = OpenAIImageGenerator.from_dict(original.to_dict())

original._client_kwargs()   # {'timeout': 120.0, 'max_retries': 10}
restored._client_kwargs()   # {'timeout': 30.0,  'max_retries': 5}

Silent: a pipeline saved and reloaded runs against different timeout and retry settings than the ones it was configured with, with nothing in the serialized dict to show it.

The two lines add both to default_to_dict, which is what OpenAIChatGenerator, OpenAITextEmbedder and OpenAIDocumentEmbedder already do. response_format stays out on purpose — it's documented as ignored and kept only for backward compatibility.

How did you test it?

Unit tests, in test/components/generators/test_openai_image_generator.py:

  • test_to_dict and test_to_dict_with_params updated. Worth noting: test_to_dict_with_params already passed timeout=60, max_retries=10 and then asserted a dict without them, which is what made this look unintentional rather than a deliberate omission.
  • test_to_dict_from_dict_roundtrip_preserves_client_settings added: it asserts through _client_kwargs(), so it fails on the observable consequence (the client is built with the wrong settings) rather than only on the shape of the dict.

All three fail without the two-line change, verified by reverting it. Full file: 23 passed, 2 skipped. ruff check and ruff format clean.

Notes for the reviewer

I found this with a small AST script that compares every @component's __init__ parameters against the keys reaching default_to_dict, after seeing the same class of defect in #3808. This is the only instance it found in this repo that survived manual verification (DocumentSplitter's splitting_function is a false positive — it's serialized separately with serialize_callable). It also flagged a few in haystack-core-integrations; I'll raise those there.

This PR was generated with an AI assistant. I have reviewed the changes and run the tests locally.

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.
  • 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.

Both are stored on the instance and feed _client_kwargs(), but to_dict dropped
them, so a saved pipeline reloaded with the OPENAI_TIMEOUT/OPENAI_MAX_RETRIES
fallbacks (30s, 5) instead of the configured values. OpenAIChatGenerator,
OpenAITextEmbedder and OpenAIDocumentEmbedder already serialize both — the
embedders since deepset-ai#9421, which fixed this same defect for them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PqBhR4HokMA14K9nLLQDTh
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner August 31, 2026 02:49
@pcbeingused333
pcbeingused333 requested review from julian-risch and removed request for a team August 31, 2026 02:49
@vercel

vercel Bot commented Aug 31, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Aug 31, 2026
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

The red Tests job here is not from this PR: test_convert_chat_completion_chunk_to_streaming_chunk and test_handle_stream_response fail on a clean main too, on all three OSes. openai 3.6.0 added compute_units, cache_write_tokens and image_tokens to the usage models, and those two tests assert an exact usage dict. Pinning openai==3.5.0 makes them pass again with nothing else changed — filed as #12519.

The release-note job was mine (single backticks in reST); fixed in b1c7440f.

test/components/generators/test_openai_image_generator.py is green: 23 passed, 2 skipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant