Guilherme Bordignon
06/29/2022, 10:26 PM@async_task()
async def get_all_objects_from_models(
models: List
):
"""
Get all objects from each model from the @param models.
"""
return await asyncio.gather(*[model.get_all_objects() for model in models])
to be used like this
all_objects_model_1, all_objects_model_2, all_objects_model_3 = get_all_objects_from_models([Model1, Model2, Model3])
the problem is that I have to pass it a nout
in the decorator or a Tuple
in the return type annotation with the number of items inside (Tuple[List, List, List]
) for this to work, otherwhise a got this error `'Task is not iterable. If your task returns multiple results, pass nout
to the task decorator/constructor, or provide a Tuple
return-type annotation to your task.',` but I would like to make this function generic and pass and return as many models as I want. Is there a way to make it work?Kevin Kho
06/30/2022, 1:03 AMnout
Anna Geller
06/30/2022, 11:53 AMYupei Chen
06/30/2022, 1:32 PM