Skip to content

[FEATURE] Purge persistent chat_data from empty entries #2732

@ria4

Description

@ria4

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions