Files
letta-server/letta/orm/errors.py
Kian Jones d592ec3135 fix: handle DBAPIError wrapping asyncpg DeadlockDetectedError (#9355)
SQLAlchemy wraps asyncpg's DeadlockDetectedError in a DBAPIError,
which was falling through to the generic 500 handler. Now detected
at both the ORM level (_handle_dbapi_error) and FastAPI handler level,
returning 409 with Retry-After header.

Datadog: https://us5.datadoghq.com/error-tracking/issue/2f1dc54c-dab6-11f0-a828-da7ad0900000

🐾 Generated with [Letta Code](https://letta.com)

Co-authored-by: Letta <noreply@letta.com>
2026-02-24 10:52:07 -08:00

31 lines
1.0 KiB
Python

class NoResultFound(Exception):
"""A record or records cannot be found given the provided search params"""
class MalformedIdError(Exception):
"""An id not in the right format, most likely violating uuid4 format."""
class UniqueConstraintViolationError(ValueError):
"""Custom exception for unique constraint violations."""
class ForeignKeyConstraintViolationError(ValueError):
"""Custom exception for foreign key constraint violations."""
class DatabaseTimeoutError(Exception):
"""Custom exception for database timeout issues."""
def __init__(self, message="Database operation timed out", original_exception=None):
super().__init__(message)
self.original_exception = original_exception
class DatabaseDeadlockError(Exception):
"""Custom exception for database deadlock errors (PostgreSQL error code 40P01)."""
def __init__(self, message="A database deadlock was detected", original_exception=None):
super().__init__(message)
self.original_exception = original_exception