diff --git a/letta/orm/sqlalchemy_base.py b/letta/orm/sqlalchemy_base.py index 3c60ab25..f9ee7452 100644 --- a/letta/orm/sqlalchemy_base.py +++ b/letta/orm/sqlalchemy_base.py @@ -5,7 +5,7 @@ from functools import wraps from pprint import pformat from typing import TYPE_CHECKING, List, Literal, Optional, Tuple, Union -from sqlalchemy import Sequence, String, and_, delete, func, or_, select, text +from sqlalchemy import Sequence, String, and_, delete, func, or_, select from sqlalchemy.exc import DBAPIError, IntegrityError, TimeoutError from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.orm import Mapped, Session, mapped_column @@ -512,14 +512,9 @@ class SqlalchemyBase(CommonSqlalchemyMetaMixins, Base): query, query_conditions = cls._read_multiple_preprocess(identifiers, actor, access, access_type, check_is_deleted, **kwargs) if query is None: raise NoResultFound(f"{cls.__name__} not found with identifier {identifier}") - if is_postgresql_session(db_session): - await db_session.execute(text("SET LOCAL enable_seqscan = OFF")) - try: - result = await db_session.execute(query) - item = result.scalar_one_or_none() - finally: - if is_postgresql_session(db_session): - await db_session.execute(text("SET LOCAL enable_seqscan = ON")) + + result = await db_session.execute(query) + item = result.scalar_one_or_none() if item is None: raise NoResultFound(f"{cls.__name__} not found with {', '.join(query_conditions if query_conditions else ['no conditions'])}") diff --git a/letta/services/user_manager.py b/letta/services/user_manager.py index 0f05e41f..ea391953 100644 --- a/letta/services/user_manager.py +++ b/letta/services/user_manager.py @@ -1,6 +1,6 @@ from typing import List, Optional -from sqlalchemy import select, text +from sqlalchemy import select from letta.constants import DEFAULT_ORG_ID from letta.data_sources.redis_client import get_redis_client @@ -8,7 +8,6 @@ from letta.helpers.decorators import async_redis_cache from letta.log import get_logger from letta.orm.errors import NoResultFound from letta.orm.organization import Organization as OrganizationModel -from letta.orm.sqlalchemy_base import is_postgresql_session from letta.orm.user import User as UserModel from letta.otel.tracing import trace_method from letta.schemas.user import User as PydanticUser @@ -157,16 +156,9 @@ class UserManager: async def get_actor_by_id_async(self, actor_id: str) -> PydanticUser: """Fetch a user by ID asynchronously.""" async with db_registry.async_session() as session: - # Turn off seqscan to force use pk index - if is_postgresql_session(session): - await session.execute(text("SET LOCAL enable_seqscan = OFF")) - try: - stmt = select(UserModel).where(UserModel.id == actor_id) - result = await session.execute(stmt) - user = result.scalar_one_or_none() - finally: - if is_postgresql_session(session): - await session.execute(text("SET LOCAL enable_seqscan = ON")) + stmt = select(UserModel).where(UserModel.id == actor_id) + result = await session.execute(stmt) + user = result.scalar_one_or_none() if not user: raise NoResultFound(f"User not found with id={actor_id}")