I trying to write a Telegram bot using AIOGRAM 3.7b.
There is a Problem occcurs with my code: RuntimeWarning: coroutine 'SyncToAsync.call' was never awaited
Code bellow: parents_handler.py
@parents_router.message(ParentsState.main)
async def parents_main(msg: Message, state: FSMContext):
tg_bot_auth = await TGBotAuth.objects.aget(tg_user_id=msg.from_user.id)
keyboard_markup, text, state_next = None, None, None
if msg.text == 'Reference application':
keyboard_markup, text, state_next = await get_reference_application_keyboard(tg_bot_auth)
elif msg.text == 'Application for exit':
keyboard_markup, text, state_next = await get_parents_student_keyboard(tg_bot_auth)
await state.set_state(state_next)
await msg.answer(text=text, reply_markup=keyboard_markup)
keyboard.py
@sync_to_async
def get_parents_student_keyboard(tg_bot_auth: TGBotAuth):
parent = tg_bot_auth.user
students = Student.objects.filter(parent=parent)
builder = ReplyKeyboardBuilder()
if len(students) == 1:
return get_date_chooser_parents(tg_bot_auth)
for student in students:
builder.button(text=str(student))
return builder.as_markup(), MESSAGES['parents_students'], ParentsState.student_choosing
error as follows:
File "/Users/shuhrat/PycharmProjects/applicationsBot/telegramBot/bot/parents_handler.py", line 29, in parents_main
keyboard_markup, text, state_next = await get_parents_student_keyboard(tg_bot_auth)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: cannot unpack non-iterable coroutine object
/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py:1920: RuntimeWarning: coroutine 'SyncToAsync.__call__' was never awaited
handle = None # Needed to break cycles when an exception occurs.
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
I'm trying to get object that should be returned