pythonitalia / python-italy-telegram-bot

Modular telegram group management bot, used for the Python Italia telegram group
https://www.python.it/comunita/
GNU General Public License v3.0
16 stars 7 forks source link

Update dispatcher loses the reference to chat_id #32

Closed MattiaFailla closed 3 years ago

MattiaFailla commented 3 years ago

The dispatcher seems to lose the chat id attribute in some edge cases.

2021-03-24T10:18:02.865940448Z Exception in thread dispatcher:
2021-03-24T10:18:02.865966237Z Traceback (most recent call last):
2021-03-24T10:18:02.865978042Z File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
2021-03-24T10:18:02.865990790Z self.run()
2021-03-24T10:18:02.865998864Z File "/usr/local/lib/python3.8/threading.py", line 870, in run
2021-03-24T10:18:02.866007262Z self._target(*self._args, **self._kwargs)
2021-03-24T10:18:02.866037764Z File "/usr/local/lib/python3.8/site-packages/telegram/ext/updater.py", line 156, in _thread_wrapper
2021-03-24T10:18:02.866048911Z target(*args, **kwargs)
2021-03-24T10:18:02.866058343Z File "/usr/local/lib/python3.8/site-packages/telegram/ext/dispatcher.py", line 228, in start
2021-03-24T10:18:02.866068267Z self.process_update(update)
2021-03-24T10:18:02.866077380Z File "/tg_bot/__main__.py", line 641, in process_update
2021-03-24T10:18:02.866086826Z cnt = CHATS_CNT.get(update.effective_chat.id, 0)
2021-03-24T10:18:02.866096096Z AttributeError: 'NoneType' object has no attribute 'id'

This lead to a process termination.

MattiaFailla commented 3 years ago

The issue seems to be related with ".message" and it's way to handle the update_message method.

MattiaFailla commented 3 years ago

I've disabled the antiflood module, since there may be an issue with the flood counter and the update_message method

MattiaFailla commented 3 years ago

A fix has been implemented in the following commit: 8da0575e55e74a18ac74222bda30edde4d573248

It seems that Telegram is sending us invalid update json data perhaps due to a network problem or a forced closure of the session. The fix simply ignore this error and the bot waits for the next update.