From d34e9c2fafd3a49a2ce9d9e364fbc400bb27cd44 Mon Sep 17 00:00:00 2001 From: AndrewKing <11490628+andrew000@users.noreply.github.com> Date: Sat, 20 Mar 2021 15:44:04 +0200 Subject: [PATCH] Add warning and log in TelegramObject.__setitem__ When Telegram adds a new field -> Aiogram will warn about this. --- aiogram/types/base.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aiogram/types/base.py b/aiogram/types/base.py index 585833ec..2a7d7b66 100644 --- a/aiogram/types/base.py +++ b/aiogram/types/base.py @@ -2,6 +2,8 @@ from __future__ import annotations import io import typing +import warnings +from asyncio.log import logger from typing import TypeVar 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)) 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: """ Check key contains in that object