-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
bot_data as global memory (V12 version of #1322) #1325
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far I've only done a quick look over, but it looks really good!
I added a few comments/questions that I'd like you to answer :)
And I think you did a good job with the pytest stuff :D
In terms of
I think the reason we do that, is that it's a user_data and chat_data is a defaultdict, with the ids (int) as the key. Oh and in terms of failed tests.. Most of them you can ignore - we're working on fixing them, but progress is slow :) |
Thanks for the comments, @jsmnbom!
Yeah, but something like
No problem. I took the liberty and fixed it for |
Please see my comments in #1301. Some of them apply here too. TLDR: not merging for inclusion in V12 beta just yet since I'm not 100% sure of the internals of persistence. |
I would like to pipe in here. I think this feature is a bit overdone. I don;t see why adding a simple dict to the bot class wouldn't serve the purpose looked for here. I know it ties in with persistence in this way, but I;m not a big fan of introducing new variable to the persistence. It's mainly created to make the ones we already had persistent. I Appreciate the time you put in to help us here, but if it;s up to me I would like to not implement this feature... |
While I'd love to have this for some of my bots, the decision clearly is up to you :D |
I see no reason for this. Providing chat/user data as a (temporary) storage is great and often used, if someone wants a global memory, they should setup a database. |
Maybe I have a different view on this since I always used IMHO, But again, this is my personal opinion and I'm not as experienced as most of @python-telegram-bot/maintainers. I have working code, still I'd love to have this feature natively. |
Yes, I would feel way better. But I would also say that this is out of the scope of this project. Normally, you would try to optimize how you build the database around your bot. Giving users a general interface would feel weird/wrong to me. I am the counterpart to you. I used chat/user data years before persistence was a thing and would never use it as a permanent storage. Temporary, great. But for everything really persistent, I use a real database. Maybe Im just too conservative though. |
@Bibo-Joshi also the persistence page in wiki will need to be updated right? |
This PR implements the global memory proposed in #1318 by providing a dictionary
bot_data
in addition touser_data
andchat_data
in a V12 compatible way (i.e. using context based callbacks, replacing #1322).Integration of
bot_data
in theDispatcher
class is provided.Since the
bot_data
is a global memory, it will always be added to aCallbackContext
(i.e. every callwill add
bot_data
tocallback_context
).Integration in persistence is also provided. Note, that in
update_bot_data
, the data is updated byin contrast to the current implentation for
user/chat_data
This is due to problems as described in #1297. However, this does not fix #1297 for
bot_data
. Whan a good way to handle those problems is found, it should be implemented forbot_data
(e.g. usage ofdeepcopy
as proposed in #1301)In
DictPersistence
, I just usedjson.loads()
to decode serialized data. Foruser_data
andchat_data
, a function from the helpers module is used to allow integer keys. imo, this is not really necessary and may lead to problems (e.g. when using'3'
as a key, that will be decoded as3
), so I left it out. If I just didn't get the point of it, I will gladly add this.Also, I've adjusted the test routines. Since I'm not familiar with the
pytest
module, please have a close look at those.