Skip to content

Dispatcher force updating persistence object's chat data attribute #1452

@CuriousGeorgiy

Description

@CuriousGeorgiy

Steps to reproduce

  1. Use the echobot2 example code with a few changes list below.

  2. In main function create a DictPersistence object with store_chat_data set to False.

  3. Create the Updater object with persistence set to the object created in the second step.

  4. Send SIGKILL to the process in which the example code is launched.

Expected behaviour

The code should normally terminate.

Actual behaviour

The code terminates with the following error:
File ".../echobot2.py", line 81, in main
updater.idle()
File ".../.venv/lib/python3.7/site-packages/telegram/ext/updater.py", line 529, in idle
sleep(1)
File ".../.venv/lib/python3.7/site-packages/telegram/ext/updater.py", line 504, in signal_handler
self.dispatcher.update_persistence()
File ".../.venv/lib/python3.7/site-packages/telegram/ext/dispatcher.py", line 437, in update_persistence
self.persistence.update_chat_data(chat_id, self.chat_data[chat_id])
File ".../.venv/lib/python3.7/site-packages/telegram/ext/dictpersistence.py", line 193, in update_chat_data
if self._chat_data.get(chat_id) == data:
AttributeError: 'NoneType' object has no attribute 'get'

Tracing back the error, it seems that when receiving the SIGKILL signal, the dispatcher is force updating the persistence object's chat data attribute without checking its store_chat_data attribute, see the following code from telegram.ext.dispatcher.py:

def update_persistence(self):
"""Update :attr:user_data and :attr:chat_data in :attr:persistence.
"""
if self.persistence:
for chat_id in self.chat_data:
self.persistence.update_chat_data(chat_id, self.chat_data[chat_id])
for user_id in self.user_data:
self.persistence.update_user_data(user_id, self.user_data[user_id])

Configuration

Operating System:
Manjaro 18.0.4 Illyria

Version of Python, python-telegram-bot & dependencies:
python-telegram-bot 12.0.0b1
certifi 2019.06.16
future 0.17.1
Python 3.7.3 (default, Jun 24 2019, 04:54:02) [GCC 9.1.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions