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
This commit adds a new file `custom_types.py` in the aiogram directory.
The inclusion of `DateTime` type ensures better compatibility with the Telegram Bot API. `DateTime` type is further enhanced to work with unixtime.
This behaviour was disabled since pydantic 2.0 in due to json_serializers was removed from models settings, so, now it can be resolved via Annotated custom types with custom serializers like:
* #1277 Replace datetime.datetime with DateTime across codebase
Replaced all instances of standard library 'datetime.datetime' with a new 'DateTime' type from `.custom` module. This change is necessary to make all date-time values compatible with the Telegram Bot API (it uses Unix time). This will simplify the conversion process and eliminate potential errors related to date-time format mismatches. Changed codebase, butcher files, and modified 'pyproject.toml' to shift the typing-extensions dependency. The 'aiogram/custom_types.py' file was renamed to 'aiogram/types/custom.py' to better reflect its nature as a location for custom types used in the aiogram library.
aiogram version
3.x
Problem
In case we want to dump current event/message/etc using model_dump_json method we get something like this:
The message.date field has its own type which is not BotAPI compatible.
Possible solution
Make aiogram types serialize to BotAPI standard.
Alternatives
No response
Code example
Additional information
No response
The text was updated successfully, but these errors were encountered: