Skip to content

JSON of model_dump_json of aiogram types are not BotAPI compatible #1277

Description

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:

{
  "update_id": 909208484,
  "message": {
    "message_id": 3171,
    "date": "2023-08-20T18:12:29Z",
    "chat": {
      "id": 483808054,
      "type": "private",
      "username": "MrYacha",
      "first_name": "Yacha"
    },
    "from": {
      "id": 483808054,
      "is_bot": false,
      "first_name": "Yacha",
      "username": "MrYacha",
      "language_code": "de",
      "is_premium": true
    },
    "text": "/notes",
    "entities": [
      {
        "type": "bot_command",
        "offset": 0,
        "length": 6
      }
    ]
  }
}

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

message.model_dump_json(exclude_none=True, by_alias=True)

Additional information

No response

Metadata

Metadata

Assignees

Labels

3.xIssue or PR for stable 3.x versionenhancementMake it better!

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
✅ Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions