Add warning and log in TelegramObject.__setitem__

When Telegram adds a new field -> Aiogram will warn about this.
This commit is contained in:
AndrewKing 2021-03-20 15:44:04 +02:00
parent 970c8b0b50
commit d34e9c2faf
No known key found for this signature in database
GPG key ID: D332A306AAA27181

View file

@ -2,6 +2,8 @@ from __future__ import annotations
import io import io
import typing import typing
import warnings
from asyncio.log import logger
from typing import TypeVar from typing import TypeVar
from babel.support import LazyProxy from babel.support import LazyProxy
@ -226,6 +228,10 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject):
return self.props[key].set_value(self, value, self.conf.get('parent', None)) return self.props[key].set_value(self, value, self.conf.get('parent', None))
self.values[key] = value self.values[key] = value
# Show and log a warning when Telegram silently adds new Fields
warnings.warn(f"Field '{key}' doesn't exist in {self.__class__}")
logger.warning(f"Field '{key}' doesn't exist in {self.__class__}")
def __contains__(self, item: str) -> bool: def __contains__(self, item: str) -> bool:
""" """
Check key contains in that object Check key contains in that object