-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Milestone
Description
What kind of feature are you missing? Where do you notice a shortcoming of PTB?
When using persistent chat_data, there's no method for purging entries which have been emptied. The chat_id key will always remain in the chat_data defaultdict. I believe it's the same for user_data.
Because of the Dispatcher.__update_persistence()
implementation, even deleting the keys with del chat_data[k]
won't remove them from the persistence file. See:
python-telegram-bot/telegram/ext/dispatcher.py
Lines 665 to 669 in bc7c422
def __update_persistence(self, update: object = None) -> None: | |
if self.persistence: | |
# We use list() here in order to decouple chat_ids from self.chat_data, as dict view | |
# objects will change, when the dict does and we want to loop over chat_ids | |
chat_ids = list(self.chat_data.keys()) |
Describe the solution you'd like
- Add a method to the Dispatcher class for removing a key from the persistence file, with the key as parameter. It should not matter to the method whether the related value is empty or not.
- Add another method for purging all orphaned keys from the persistence file.
There probably should be 4 methods, 2 for chat_data
and 2 for user_data
.
Describe alternatives you've considered
No response
Additional context
No response