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
What kind of feature are you missing? Where do you notice a shortcoming of PTB?
When TG deprecates attributes, we usually convert them to properties in our classes and issue a warning on access. For this, we rename Class.attribute to Class.._attribute. This leads to problems on un-pickling data that was pickled with previous versions. While this is okay acccording to our stability policy, it would still be nice to handle this better for the users
Describe the solution you'd like
In TelegramObjejct.__setstate__, the current logic is
# catch cases when old attributes are removed from new versions
api_kwargs[key] =val# add it to api_kwargs as fallback
# For api_kwargs we first apply any kwargs that are already attributes of the object
# and then set the rest as MappingProxyType attribute. Converting to MappingProxyType
# is necessary, since __getstate__ converts it to a dict as MPT is not pickable.
self._apply_api_kwargs(api_kwargs)
self.api_kwargs=MappingProxyType(api_kwargs)
I would like to change this to
first try set_attr
check if the attribute name is a property
if yes, try setting _attributename (unless the name already starts with underscore)
if that fails or the attribute is not a property, put the attribute into api_kwargs - unless the attribute has a leading underscore. This last part is for when we finally completely remove the property - pickling with the property in place and unpickling without the property in the new version will then simply remove the attribute.
As a 'victim' of this unfortunate upgrading consequence, I would like to add that - while 'doing nothing' is of course a valid course of action, it would be nice to at least having the un-pickling continue, skipping the deprecated attributes - even with a loss of data - instead of totally crashing and being de-facto locked out of the pickle file.
@harshil21 For reference: it's also possible to directly check if something is a property: https://stackoverflow.com/a/17735709
Try-except may still be viewed as more elegant, I guess. I'll leave that up to you:)
What kind of feature are you missing? Where do you notice a shortcoming of PTB?
When TG deprecates attributes, we usually convert them to properties in our classes and issue a warning on access. For this, we rename
Class.attribute
toClass.._attribute
. This leads to problems on un-pickling data that was pickled with previous versions. While this is okay acccording to our stability policy, it would still be nice to handle this better for the usersDescribe the solution you'd like
In
TelegramObjejct.__setstate__
, the current logic ispython-telegram-bot/telegram/_telegramobject.py
Lines 311 to 322 in 1cf63c2
I would like to change this to
api_kwargs
- unless the attribute has a leading underscore. This last part is for when we finally completely remove the property - pickling with the property in place and unpickling without the property in the new version will then simply remove the attribute.Moreover, in
_apply_api_kwargs
python-telegram-bot/telegram/_telegramobject.py
Lines 492 to 494 in 1cf63c2
we can first check if tha attribute is a property
Describe alternatives you've considered
Do nothing as we didn't promise that this works.
Additional context
https://t.me/pythontelegrambotgroup/723964
The text was updated successfully, but these errors were encountered: