Skip to content

[BUG] Persistence of Bots #1992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Bibo-Joshi opened this issue Jun 10, 2020 · 1 comment
Closed

[BUG] Persistence of Bots #1992

Bibo-Joshi opened this issue Jun 10, 2020 · 1 comment

Comments

@Bibo-Joshi
Copy link
Member

Steps to reproduce

  1. Add an object with a bot attribute to e.g. chat_data and persist it

  2. Change the bots token and restart the updater

Expected behaviour

The reloaded bot should have the new token.

Actual behaviour

The bot in the loaded chat_data still has the old token. Similar for the other bot attributes

Proposed solution

  1. Remove __reduce__ from Bot , as we don't want to encourage pickling bots

  2. Add static methods replace_bots(object) and set_bots(objects, bot) (or other naming) to BasePersistence, where replace_bots implements the logic to replace every Bot instance in an object, be it a dict, a list, a custom object … with some special placeholder BOT_INSTANCE or whatever and set_bots in turn replaces BOT_INSTANCE with the given bot. To make get_*_data and update_*_data use those, we have several options:

    1. Just call them in get/update_. Custom subclasses of BasePersistence will have to adjust.
    2. Add a __new__ method to make the get/update_ methods call the methods under the hood. that way custom subclasses don't need to change anything
    3. Add methods get/update_*_replace_bot, which call set/replace_bots and before/after get/update_*. Use those in Updater. This way, custom classes also don't need to be changed.

    don't know, whats better …

  3. Alternatively to passing the bot to set_bots, we could add set_bot to BasePersistence so that we can use self.bot in set_bot. That would save us from having to pass bot to get_* as well

@Bibo-Joshi
Copy link
Member Author

#1994 was merged into v13, so I'll close this

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant