From c2b00b0cece979d499a46907bc80bd99f0442809 Mon Sep 17 00:00:00 2001 From: Cadu Date: Sun, 25 Jan 2026 22:47:22 -0300 Subject: [PATCH] Fix SAWarning in lambda_stmt test by using selectinload instead of subqueryload subqueryload has caching issues with lambda_stmt, causing SQLAlchemy to emit a warning recommending selectinload for more effective full-lambda caching. --- tests/default_config/test_queries.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/default_config/test_queries.py b/tests/default_config/test_queries.py index ebc751b..46f90a4 100644 --- a/tests/default_config/test_queries.py +++ b/tests/default_config/test_queries.py @@ -605,12 +605,13 @@ def test_lambda_stmt_with_selectinload(seeded_session, rewriter): assert parent.children[0].deleted_at is None -def test_lambda_stmt_with_subqueryload(seeded_session, rewriter): - """Test lambda_stmt combined with subqueryload eager loading. +def test_lambda_stmt_with_selectinload_multiple_children(seeded_session, rewriter): + """Test lambda_stmt combined with selectinload eager loading with multiple children. - subqueryload uses a subquery to load all related records. + selectinload uses a SELECT IN to load all related records. + Note: subqueryload is not used here because it has caching issues with lambda_stmt. """ - stmt = lambda_stmt(lambda: select(SDParent).options(subqueryload(SDParent.children)).where(SDParent.id == 1000)) + stmt = lambda_stmt(lambda: select(SDParent).options(selectinload(SDParent.children)).where(SDParent.id == 1000)) result = seeded_session.execute(stmt) parent = result.scalars().unique().first()