mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
refactor(base.py): optimize JSON serialization logic (dev-3.x)
Refactor JSON serialization to handle non-TelegramObject cases earlier. Ensures proper serialization when Union[Any, TelegramObject] is used.
This commit is contained in:
parent
879168f938
commit
7bd8f64630
1 changed files with 7 additions and 7 deletions
|
|
@ -47,13 +47,13 @@ class TelegramObject(BotContextController, BaseModel):
|
|||
Replacing `Default` placeholders with actual values from bot defaults.
|
||||
Ensures JSON serialization backward compatibility by handling non-standard objects.
|
||||
"""
|
||||
if isinstance(self, TelegramObject):
|
||||
properties = self.bot.default if self.bot else DefaultBotProperties()
|
||||
default_fields = {
|
||||
key: properties[value.name] for key, value in self if isinstance(value, Default)
|
||||
}
|
||||
return serializer(self.model_copy(update=default_fields))
|
||||
return serializer(self) # FIXME: why non-TelegramObject passed there?
|
||||
if not isinstance(self, TelegramObject):
|
||||
return serializer(self) # Can be passed when using Union[Any, TelegramObject]
|
||||
properties = self.bot.default if self.bot else DefaultBotProperties()
|
||||
default_fields = {
|
||||
key: properties[value.name] for key, value in self if isinstance(value, Default)
|
||||
}
|
||||
return serializer(self.model_copy(update=default_fields))
|
||||
|
||||
|
||||
class MutableTelegramObject(TelegramObject):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue