Skip to content

Commit

Permalink
fix: clear other chat contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
milselarch committed Nov 22, 2024
1 parent 0a51c2b commit dc46d7b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
10 changes: 9 additions & 1 deletion database/callback_context_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,19 @@ def get_context_type(self) -> ChatContextStateTypes:
def save_state(self) -> CallbackContextState:
user_id = self.get_user_id()
chat_id = self.get_chat_id()
context_type = self.get_context_type()

with database_proxy.atomic():
# delete other chat contexts in the same chat
CallbackContextState.delete().where(
(CallbackContextState.user == user_id) &
(CallbackContextState.chat_id == chat_id) &
(CallbackContextState.context_type != context_type)
).execute()
# get existing chat context and update it
context_state, _ = CallbackContextState.build_from_fields(
user_id=user_id, chat_id=chat_id,
context_type=self.get_context_type()
context_type=context_type
).get_or_create()

context_state.update_state(self)
Expand Down
26 changes: 26 additions & 0 deletions logs/log_events.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1098,3 +1098,29 @@ task: <Task pending name='Task-2' coro=<RankedChoiceBot._call_polling_tasks_rout
2024-11-22 21:53:01,334 - __main__ - WARNING - <<< INITIALIZING >>>
2024-11-22 21:53:04,671 - asyncio - ERROR - Task was destroyed but it is pending!
task: <Task pending name='Task-2' coro=<RankedChoiceBot._call_polling_tasks_routine() running at /home/milselarch/projects/SUTD/voting-bot/bot.py:93> wait_for=<Future pending cb=[Task.task_wakeup()]>>
2024-11-22 23:45:57,745 - __main__ - WARNING - <<< INITIALIZING >>>
2024-11-22 23:46:46,663 - telegram.ext.Application - ERROR - No error handlers are registered, logging exception.
Traceback (most recent call last):
File "/home/milselarch/projects/SUTD/voting-bot/venv/lib/python3.12/site-packages/telegram/ext/_application.py", line 1335, in process_update
await coroutine
File "/home/milselarch/projects/SUTD/voting-bot/venv/lib/python3.12/site-packages/telegram/ext/_handlers/basehandler.py", line 158, in handle_update
return await self.callback(update, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/milselarch/projects/SUTD/voting-bot/tele_helpers.py", line 190, in caller
return await func(modified_tele_update, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/milselarch/projects/SUTD/voting-bot/bot.py", line 378, in create_group_poll
return await self.create_poll(
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/milselarch/projects/SUTD/voting-bot/bot.py", line 430, in create_poll
).save_state()
^^^^^^^^^^^^
File "/home/milselarch/projects/SUTD/voting-bot/database/callback_context_state.py", line 115, in save_state
{CallbackContextState.user == user_id} &
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'Expression'
2024-11-22 23:47:06,551 - asyncio - ERROR - Task was destroyed but it is pending!
task: <Task pending name='Task-2' coro=<RankedChoiceBot._call_polling_tasks_routine() running at /home/milselarch/projects/SUTD/voting-bot/bot.py:93> wait_for=<Future pending cb=[Task.task_wakeup()]>>
2024-11-22 23:47:07,783 - __main__ - WARNING - <<< INITIALIZING >>>
2024-11-22 23:48:04,976 - asyncio - ERROR - Task was destroyed but it is pending!
task: <Task pending name='Task-2' coro=<RankedChoiceBot._call_polling_tasks_routine() running at /home/milselarch/projects/SUTD/voting-bot/bot.py:93> wait_for=<Future pending cb=[Task.task_wakeup()]>>

0 comments on commit dc46d7b

Please sign in to comment.