fix(router): lazy-import InternalServerError to break cyclic import

This commit is contained in:
michelligabriele 2026-04-13 19:47:30 +02:00
parent 597cd0000d
commit 9edc10a543
No known key found for this signature in database

View file

@ -10,7 +10,6 @@ from litellm.exceptions import (
AuthenticationError,
BadRequestError,
ContentPolicyViolationError,
InternalServerError,
RateLimitError,
Timeout,
)
@ -31,6 +30,11 @@ def get_num_retries_from_retry_policy(
ContentPolicyViolationErrorRetries: Optional[int] = None
InternalServerErrorRetries: Optional[int] = None
"""
# Lazy import: `InternalServerError` is defined late in `litellm/exceptions.py`,
# after a cyclic import re-enters this module during exceptions.py evaluation.
# A module-level import would be flagged by CodeQL as potentially undefined.
from litellm.exceptions import InternalServerError
# if we can find the exception then in the retry policy -> return the number of retries
if (