-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Description
Steps to reproduce
-
Add an object with a bot attribute to e.g.
chat_dataand persist it -
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
-
Remove
__reduce__fromBot, as we don't want to encourage pickling bots -
Add static methods
replace_bots(object)andset_bots(objects, bot)(or other naming) toBasePersistence, wherereplace_botsimplements the logic to replace everyBotinstance in an object, be it a dict, a list, a custom object … with some special placeholderBOT_INSTANCEor whatever andset_botsin turn replacesBOT_INSTANCEwith the given bot. To makeget_*_dataandupdate_*_datause those, we have several options:- Just call them in
get/update_. Custom subclasses ofBasePersistencewill have to adjust. - Add a
__new__method to make theget/update_methods call the methods under the hood. that way custom subclasses don't need to change anything - Add methods
get/update_*_replace_bot, which callset/replace_botsand before/afterget/update_*. Use those inUpdater. This way, custom classes also don't need to be changed.
don't know, whats better …
- Just call them in
-
Alternatively to passing the bot to
set_bots, we could addset_bottoBasePersistenceso that we can useself.botinset_bot. That would save us from having to passbottoget_*as well