@@ -312,10 +312,16 @@ async def test_get_thread_by_class_id_preloads_export_user_fields(db):
312312 last_name = "User" ,
313313 anonymous_link = share_link ,
314314 )
315+ second_user = models .User (
316+ email = "export-user-2@example.com" ,
317+ display_name = "Second Export User" ,
318+ first_name = "Second" ,
319+ last_name = "User" ,
320+ )
315321 thread = models .Thread (
316322 thread_id = "thread_export_user_fields" ,
317323 class_ = class_ ,
318- users = [user ],
324+ users = [user , second_user ],
319325 display_user_info = True ,
320326 )
321327 session .add (thread )
@@ -331,7 +337,10 @@ async def test_get_thread_by_class_id_preloads_export_user_fields(db):
331337 ]
332338
333339 assert len (threads ) == 1
334- loaded_user = threads [0 ].users [0 ]
340+ assert len (threads [0 ].users ) == 2
341+ loaded_user = next (
342+ user for user in threads [0 ].users if user .email == "export-user@example.com"
343+ )
335344 unloaded = inspect (loaded_user ).unloaded
336345
337346 assert "id" not in unloaded
@@ -433,6 +442,56 @@ async def test_get_thread_by_class_id_filters_by_assistant_ids(db):
433442 ]
434443
435444
445+ @pytest .mark .asyncio
446+ async def test_get_thread_by_class_id_empty_user_filter_returns_no_threads (db ):
447+ async with db .async_session () as session :
448+ class_ = models .Class (name = "Export Thread Empty User Filter Class" )
449+ thread = models .Thread (
450+ thread_id = "thread_export_empty_user_filter" ,
451+ class_ = class_ ,
452+ )
453+ session .add (thread )
454+ await session .commit ()
455+ class_id = class_ .id
456+
457+ async with db .async_session () as session :
458+ threads = [
459+ t
460+ async for t in models .Thread .get_thread_by_class_id (
461+ session ,
462+ class_id = class_id ,
463+ include_only_user_ids = [],
464+ )
465+ ]
466+
467+ assert threads == []
468+
469+
470+ @pytest .mark .asyncio
471+ async def test_get_thread_by_class_id_empty_assistant_filter_returns_no_threads (db ):
472+ async with db .async_session () as session :
473+ class_ = models .Class (name = "Export Thread Empty Assistant Filter Class" )
474+ thread = models .Thread (
475+ thread_id = "thread_export_empty_assistant_filter" ,
476+ class_ = class_ ,
477+ )
478+ session .add (thread )
479+ await session .commit ()
480+ class_id = class_ .id
481+
482+ async with db .async_session () as session :
483+ threads = [
484+ t
485+ async for t in models .Thread .get_thread_by_class_id (
486+ session ,
487+ class_id = class_id ,
488+ include_only_assistant_ids = [],
489+ )
490+ ]
491+
492+ assert threads == []
493+
494+
436495@pytest .mark .asyncio
437496async def test_list_messages_tool_calls_excludes_hidden_messages_by_default (db ):
438497 async with db .async_session () as session :
0 commit comments