fix: remove contains_eager conflicting with selectinload on user relationship

Loader strategies for the same ORM path cannot coexist. The
_apply_user_join_filter helper added contains_eager(model.user) on top
of the selectinload(Model.user) already present in each query, causing
InvalidRequestError at runtime. Removed contains_eager — selectinload
handles user loading correctly on its own.
This commit is contained in:
Fringg
2026-03-18 05:50:00 +03:00
parent ad268329be
commit fddf8ef5eb
+1 -2
View File
@@ -11,7 +11,7 @@ from typing import Any
import structlog
from sqlalchemy import cast, desc, or_, select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import contains_eager, selectinload
from sqlalchemy.orm import selectinload
from sqlalchemy.types import String as SAString
from app.database.models import (
@@ -225,7 +225,6 @@ def _apply_user_join_filter(
) -> Any:
"""Apply user-based search filters by joining the User table."""
stmt = stmt.join(User, model.user_id == User.id)
stmt = stmt.options(contains_eager(model.user))
if search_kind == _UserSearchKind.USERNAME:
username = search_value.lstrip('@')
stmt = stmt.where(User.username.ilike(f'%{_escape_like(username)}%'))