Skip to content

fix(translator): guard rate_limit_params before .get() in do_llm_translate - #623

Closed
Morningstar202604 wants to merge 1 commit into
funstory-ai:mainfrom
Morningstar202604:fix/rate-limit-params-none
Closed

Morningstar202604 wants to merge 1 commit into
funstory-ai:mainfrom
Morningstar202604:fix/rate-limit-params-none

Conversation

@Morningstar202604

@Morningstar202604 Morningstar202604 commented Sep 29, 2026 •

Copy link
Copy Markdown

Description

OpenAITranslator.do_llm_translate dereferences rate_limit_params.get(...) whenever enable_json_mode_if_requested is set, but llm_translate() forwards its rate_limit_params with a default of None:

def llm_translate(self, text, ignore_cache=False, rate_limit_params: dict = None):
    ...
    translation = self.do_llm_translate(text, rate_limit_params)  # may be None

A caller that does not supply rate_limit_params (e.g. a custom translator subclass built on OpenAITranslator with json mode enabled) crashes with AttributeError: 'NoneType' object has no attribute 'get'.

The fix adds the same truthiness guard already used in babeldoc/tools/executor/translator.py.

Verified: None, {}, {"request_json_mode": False} and {"request_json_mode": True} all evaluate without error.


Summary by cubic

Fixes a crash in OpenAITranslator.do_llm_translate when rate_limit_params is None and JSON mode is enabled.

  • Adds a None guard before calling .get() on rate_limit_params, matching the existing guard in translator.py.
  • Callers that omit rate_limit_params (e.g., custom translator subclasses) no longer raise AttributeError.

Written for commit 1c70cd9. Summary will update on new commits.

Review in cubic

…slate

do_llm_translate dereferences rate_limit_params.get(...) when
enable_json_mode_if_requested is set, but llm_translate() passes its
rate_limit_params through with a default of None. A caller that does not
supply rate_limit_params (e.g. a custom translator built on
OpenAITranslator) then crashes with AttributeError: 'NoneType' object has
no attribute 'get'. Match the guard already used in
babeldoc/tools/executor/translator.py.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant