fix(proxy): restore broad is_database_connection_error; add is_database_transport_error for reconnect - #21796
Conversation
…se_transport_error for reconnect Any PrismaError should be treated as a DB connection error for the allow_requests_on_db_unavailable feature and 503 responses. The narrow keyword-based check is now in is_database_transport_error, which is what the reconnect logic in auth_checks.py should use. Fixes test_delete_access_group_503_on_db_connection_error and test_handle_authentication_error_db_unavailable failures caused by PR #21706 narrowing is_database_connection_error.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes a regression from #21706 by splitting database error classification into two functions with distinct purposes:
Key observations:
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/proxy/db/exception_handler.py | Restores broad is_database_connection_error (any PrismaError → True) for 503/allow-on-unavailable logic; adds narrow is_database_transport_error for reconnect logic. Clean separation of concerns. |
| litellm/proxy/auth/auth_checks.py | Single-line change: reconnect call site now uses is_database_transport_error instead of is_database_connection_error, correctly avoiding reconnect attempts for data-layer errors. |
| tests/test_litellm/proxy/db/test_exception_handler.py | Renamed test to cover is_database_transport_error for non-connection PrismaErrors. No network calls; mock-only. Could benefit from an additional test asserting the broadened is_database_connection_error returns True for data-layer PrismaErrors. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Exception raised from DB operation] --> B{Exception type?}
B -->|httpx.ConnectError / ReadError / ReadTimeout| C[DB_CONNECTION_ERROR_TYPES]
B -->|prisma.errors.PrismaError subclass| D{Which check?}
B -->|ProxyException no_db_connection| E[Both checks return True]
B -->|Other Exception| F[Both checks return False]
C --> G["is_database_connection_error → True"]
C --> H["is_database_transport_error → True"]
D -->|is_database_connection_error| I["Always True — any PrismaError qualifies"]
D -->|is_database_transport_error| J{Error message has connection keywords?}
J -->|Yes: 'can't reach', 'timed out', etc.| K["True — trigger reconnect"]
J -->|No: UniqueViolation, DataError, etc.| L["False — skip reconnect"]
I --> M["Used for: 503 responses, allow_requests_on_db_unavailable"]
K --> N["Used for: reconnect logic in auth_checks.py"]
L --> O["DB is reachable — reconnect is pointless"]
Last reviewed commit: 6f71cd4
Additional Comments (1)
The health watchdog loop still uses With the broadened For consistency with |
…se_transport_error for reconnect (BerriAI#21796) Any PrismaError should be treated as a DB connection error for the allow_requests_on_db_unavailable feature and 503 responses. The narrow keyword-based check is now in is_database_transport_error, which is what the reconnect logic in auth_checks.py should use. Fixes test_delete_access_group_503_on_db_connection_error and test_handle_authentication_error_db_unavailable failures caused by PR BerriAI#21706 narrowing is_database_connection_error.
Relevant issues
Fixes regression from #21706 which narrowed
is_database_connection_errorto only matchPrismaErrorwith specific connection keywords. This broke:test_delete_access_group_503_on_db_connection_error(assert 500 == 503)test_handle_authentication_error_db_unavailable[prisma_error*](10 parametrized tests)Changes
litellm/proxy/db/exception_handler.pyis_database_connection_errorto treat anyPrismaErroras a DB connection error — this is what drives 503 responses andallow_requests_on_db_unavailableis_database_transport_errorwith the narrow keyword-based check — only for reconnect logic where we need to distinguish "DB unreachable" from "DB returned a data error like UniqueViolationError"litellm/proxy/auth/auth_checks.pyis_database_transport_errorinstead ofis_database_connection_errortests/test_litellm/proxy/db/test_exception_handler.pytest_is_database_connection_error_non_connection_prisma_errors→test_is_database_transport_error_non_connection_prisma_errorsis_database_transport_error(data-layer errors should not trigger reconnect, but they should still trigger 503)Pre-Submission checklist
is_database_transport_errormake test-unitpasses locallyType
Changes