You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an object with a bot attribute to e.g. chat_data and 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__ from Bot , as we don't want to encourage pickling bots
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:
Just call them in get/update_. Custom subclasses of BasePersistence will have to adjust.
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
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 …
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
The text was updated successfully, but these errors were encountered:
Steps to reproduce
Add an object with a bot attribute to e.g.
chat_data
and persist itChange 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 attributesProposed solution
Remove
__reduce__
fromBot
, as we don't want to encourage pickling botsAdd static methods
replace_bots(object)
andset_bots(objects, bot)
(or other naming) toBasePersistence
, wherereplace_bots
implements the logic to replace everyBot
instance in an object, be it a dict, a list, a custom object … with some special placeholderBOT_INSTANCE
or whatever andset_bots
in turn replacesBOT_INSTANCE
with the given bot. To makeget_*_data
andupdate_*_data
use those, we have several options:get/update_
. Custom subclasses ofBasePersistence
will have to adjust.__new__
method to make theget/update_
methods call the methods under the hood. that way custom subclasses don't need to change anythingget/update_*_replace_bot
, which callset/replace_bots
and before/afterget/update_*
. Use those inUpdater
. This way, custom classes also don't need to be changed.don't know, whats better …
Alternatively to passing the bot to
set_bots
, we could addset_bot
toBasePersistence
so that we can useself.bot
inset_bot
. That would save us from having to passbot
toget_*
as wellThe text was updated successfully, but these errors were encountered: