77
88
99try :
10- from sqlalchemy import Table , and_ , delete , select
10+ from sqlalchemy import ColumnElement , Table , and_ , delete , select
1111 from sqlalchemy .ext .asyncio import (
1212 AsyncEngine ,
1313 AsyncSession ,
@@ -304,24 +304,14 @@ async def set_info(
304304 owner ,
305305 )
306306
307- async def get_info (
307+ async def _select_configs (
308308 self ,
309- task_id : str ,
310- context : ServerCallContext ,
309+ * predicates : 'ColumnElement[bool]' ,
311310 ) -> list [TaskPushNotificationConfig ]:
312- """Retrieves all push notification configurations for a task, for the given owner.
313-
314- Used by the user-callable read endpoints.
315- """
311+ """Loads configs matching the given predicates and decodes them."""
316312 await self ._ensure_initialized ()
317- owner = self .owner_resolver (context )
318313 async with self .async_session_maker () as session :
319- stmt = select (self .config_model ).where (
320- and_ (
321- self .config_model .task_id == task_id ,
322- self .config_model .owner == owner ,
323- )
324- )
314+ stmt = select (self .config_model ).where (and_ (* predicates ))
325315 result = await session .execute (stmt )
326316 models = result .scalars ().all ()
327317
@@ -334,10 +324,25 @@ async def get_info(
334324 'Could not deserialize push notification config for task %s, config %s, owner %s' ,
335325 model .task_id ,
336326 model .config_id ,
337- owner ,
327+ model . owner ,
338328 )
339329 return configs
340330
331+ async def get_info (
332+ self ,
333+ task_id : str ,
334+ context : ServerCallContext ,
335+ ) -> list [TaskPushNotificationConfig ]:
336+ """Retrieves all push notification configurations for a task, for the given owner.
337+
338+ Used by the user-callable read endpoints.
339+ """
340+ owner = self .owner_resolver (context )
341+ return await self ._select_configs (
342+ self .config_model .task_id == task_id ,
343+ self .config_model .owner == owner ,
344+ )
345+
341346 async def get_info_for_dispatch (
342347 self ,
343348 task_id : str ,
@@ -346,26 +351,9 @@ async def get_info_for_dispatch(
346351
347352 Used by the push-notification dispatch path.
348353 """
349- await self ._ensure_initialized ()
350- async with self .async_session_maker () as session :
351- stmt = select (self .config_model ).where (
352- self .config_model .task_id == task_id
353- )
354- result = await session .execute (stmt )
355- models = result .scalars ().all ()
356-
357- configs = []
358- for model in models :
359- try :
360- configs .append (self ._from_orm (model ))
361- except ValueError : # noqa: PERF203
362- logger .exception (
363- 'Could not deserialize push notification config for task %s, config %s, owner %s' ,
364- model .task_id ,
365- model .config_id ,
366- model .owner ,
367- )
368- return configs
354+ return await self ._select_configs (
355+ self .config_model .task_id == task_id ,
356+ )
369357
370358 async def delete_info (
371359 self ,
0 commit comments