Skip to content

Fix mutable default argument and unreachable exception handler#3775

Open
Mr-Neutr0n wants to merge 1 commit intolm-sys:mainfrom
Mr-Neutr0n:fix/mutable-default-and-exception-order
Open

Fix mutable default argument and unreachable exception handler#3775
Mr-Neutr0n wants to merge 1 commit intolm-sys:mainfrom
Mr-Neutr0n:fix/mutable-default-and-exception-order

Conversation

@Mr-Neutr0n
Copy link

Summary

  • fastchat/serve/gradio_block_arena_anony.py: Replace mutable default argument sampling_boost_models=[] with None in get_sample_weight(). Mutable defaults are shared across all calls and can lead to subtle, hard-to-diagnose bugs when the list is mutated.

  • fastchat/llm_judge/common.py: Reorder exception handlers in chat_completion_openai_azure() so that openai.error.InvalidRequestError is caught before its parent class openai.error.OpenAIError. The previous ordering made the InvalidRequestError handler unreachable dead code, meaning invalid request errors were retried instead of breaking immediately.

Test plan

  • Verified get_sample_weight() still works correctly with and without sampling_boost_models argument
  • Verified exception handler ordering now catches InvalidRequestError before the generic OpenAIError
  • No functional changes beyond the bug fixes

- Replace mutable default list `sampling_boost_models=[]` with `None`
  in `get_sample_weight()` to avoid the well-known mutable default
  argument pitfall (gradio_block_arena_anony.py).

- Reorder exception handlers in `chat_completion_openai_azure()` so
  `InvalidRequestError` is caught before its parent `OpenAIError`.
  The previous ordering made the `InvalidRequestError` handler
  unreachable dead code (llm_judge/common.py).
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