fix(utils): re-raise in timed_with_status when no fallback configured#1524
Open
Ptah-CT wants to merge 1 commit intoMemTensor:mainfrom
Open
fix(utils): re-raise in timed_with_status when no fallback configured#1524Ptah-CT wants to merge 1 commit intoMemTensor:mainfrom
Ptah-CT wants to merge 1 commit intoMemTensor:mainfrom
Conversation
The except branch in timed_with_status caught every exception, ran the optional fallback if configured, but otherwise let the function fall through to the implicit return None. Decorated functions like OpenAILLM.generate then returned None on a 4xx/5xx without surfacing the underlying error, and callers crashed later with confusing AttributeErrors (e.g. clean_json_response receiving None). Add an explicit `raise` so the failure propagates when no fallback is configured. Existing fallback semantics are unchanged. Repro: configure MOS_CHAT_MODEL=MiniMax-M2.7 with OPENAI_API_BASE pointed at the MiniMax v1 endpoint, then POST /product/suggestions with a body whose suggestion prompt contains only a system message. MiniMax replies 400 'chat content is empty (2013)', the decorator swallows the BadRequestError, generate() returns None, and suggestion_handler then dies in clean_json_response with 'NoneType object has no attribute replace'. With this patch the BadRequestError reaches the handler intact and the user sees the real 400 instead of a misleading AttributeError.
This was referenced Apr 22, 2026
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.
Fixes #1523.
Problem
timed_with_statuscaught every exception, ran the optionalfallback, but when no fallback was configured the wrapper fell through to an implicitreturn None. Decorated functions returnedNoneon any failure instead of raising.Concrete consequence:
OpenAILLM.generate(decorated with this) returnedNoneon a MiniMax 400 (chat content is empty (2013)for system-only messages), and the suggestion handler then died inclean_json_responsewithAttributeError: 'NoneType' object has no attribute 'replace'. The real 400 was hidden.Change
Add a single
raiseafter the fallback branch:finallystill runs, so the timing/status log line is unchanged.Type
Tested
MOS_CHAT_MODEL=MiniMax-M2.7,OPENAI_API_BASE=https://api.minimax.io/v1, system-only suggestion prompt.'NoneType' object has no attribute 'replace'openai.BadRequestError: 400 ... invalid params, chat content is empty (2013)to the caller, exactly as[TIMER_WITH_STATUS]already logged.fallback=arg supplied) is exercised by other handlers; behaviour unchanged becauseraiseis reached only when no fallback returns.Checklist