Fix random handlers

This commit is contained in:
2023-05-06 18:47:26 +02:00
parent 1f4422a9cd
commit 183351ed68
5 changed files with 15 additions and 2 deletions

View File

@@ -315,7 +315,7 @@ class GetRandomService(Generic[MODEL, QUERY], BaseService[MODEL, QUERY]):
cls,
query: QUERY,
redis: aioredis.Redis,
) -> int:
) -> int | None:
cached_object_id = await cls._get_random_object_from_cache(query, redis)
if cached_object_id is not None:
@@ -325,6 +325,9 @@ class GetRandomService(Generic[MODEL, QUERY], BaseService[MODEL, QUERY]):
await cls.cache_object_ids(query, object_ids, redis)
if len(object_ids):
return None
return choice(object_ids)