Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pydantic error when importing Bot from aiogram #1323

Closed
2 tasks done
diprog opened this issue Sep 25, 2023 · 2 comments
Closed
2 tasks done

pydantic error when importing Bot from aiogram #1323

diprog opened this issue Sep 25, 2023 · 2 comments
Labels
bug Something is wrong with the framework

Comments

@diprog
Copy link

diprog commented Sep 25, 2023

Checklist

  • I am sure the error is coming from aiogram code
  • I have searched in the issue tracker for similar bug reports, including closed ones

Operating system

Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-155-generic x86_64) / 22.04

Python version

3.11.5

aiogram version

3.1.0/3.0.0

Expected behavior

Correct import of Bot from aiogram.

Current behavior

Import failes with the exception provided in the logs.

Steps to reproduce

  1. Create a virtual enviroment with any supported version of python.
  2. Install a fresh version of aiogram (3.1.0) - pip install aiogram
  3. Import Bot from aiogram - from aiogram import Bot
  4. Catch the exception.

Code example

from aiogram import Bot

Logs

Traceback (most recent call last):
  File "/root/workzilla-tg-bot/main.py", line 5, in <module>
    import bot
  File "/root/workzilla-tg-bot/bot.py", line 3, in <module>
    from aiogram import Bot
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/aiogram/__init__.py", line 5, in <module>
    from . import enums, methods, types
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/aiogram/methods/__init__.py", line 6, in <module>
    from .answer_web_app_query import AnswerWebAppQuery
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/aiogram/methods/answer_web_app_query.py", line 31, in <module>
    class AnswerWebAppQuery(TelegramMethod[SentWebAppMessage]):
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 184, in __new__
    complete_model_class(
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 495, in complete_model_class
    schema = apply_discriminators(simplify_schema_references(schema))
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 519, in simplify_schema_references
    schema = walk_core_schema(schema, count_refs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 439, in walk_core_schema
    return f(schema, _dispatch)
           ^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 515, in count_refs
    recurse(state['definitions'][ref], count_refs)
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 215, in walk
    return f(schema, self._walk)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 503, in count_refs
    return recurse(s, count_refs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 218, in _walk
    schema = self._schema_type_to_method[schema['type']](schema, f)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 227, in _handle_other_schemas
    schema['schema'] = self.walk(sub_schema, f)  # type: ignore
                       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 215, in walk
    return f(schema, self._walk)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 503, in count_refs
    return recurse(s, count_refs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 218, in _walk
    schema = self._schema_type_to_method[schema['type']](schema, f)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 227, in _handle_other_schemas
    schema['schema'] = self.walk(sub_schema, f)  # type: ignore
                       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 215, in walk
    return f(schema, self._walk)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 503, in count_refs
    return recurse(s, count_refs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 218, in _walk
    schema = self._schema_type_to_method[schema['type']](schema, f)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 362, in handle_model_fields_schema
    replaced_field['schema'] = self.walk(v['schema'], f)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 215, in walk
    return f(schema, self._walk)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 503, in count_refs
    return recurse(s, count_refs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 218, in _walk
    schema = self._schema_type_to_method[schema['type']](schema, f)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 323, in handle_union_schema
    new_choices.append(self.walk(v, f))
                       ^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 215, in walk
    return f(schema, self._walk)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 515, in count_refs
    recurse(state['definitions'][ref], count_refs)
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 218, in _walk
    schema = self._schema_type_to_method[schema['type']](schema, f)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 227, in _handle_other_schemas
    schema['schema'] = self.walk(sub_schema, f)  # type: ignore
                       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 215, in walk
    return f(schema, self._walk)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 503, in count_refs
    return recurse(s, count_refs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 218, in _walk
    schema = self._schema_type_to_method[schema['type']](schema, f)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 227, in _handle_other_schemas
    schema['schema'] = self.walk(sub_schema, f)  # type: ignore
                       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 215, in walk
    return f(schema, self._walk)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 503, in count_refs
    return recurse(s, count_refs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 218, in _walk
    schema = self._schema_type_to_method[schema['type']](schema, f)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 362, in handle_model_fields_schema
    replaced_field['schema'] = self.walk(v['schema'], f)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 215, in walk
    return f(schema, self._walk)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 503, in count_refs
    return recurse(s, count_refs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 218, in _walk
    schema = self._schema_type_to_method[schema['type']](schema, f)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 227, in _handle_other_schemas
    schema['schema'] = self.walk(sub_schema, f)  # type: ignore
                       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 215, in walk
    return f(schema, self._walk)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 503, in count_refs
    return recurse(s, count_refs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 218, in _walk
    schema = self._schema_type_to_method[schema['type']](schema, f)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 227, in _handle_other_schemas
    schema['schema'] = self.walk(sub_schema, f)  # type: ignore
                       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 215, in walk
    return f(schema, self._walk)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 503, in count_refs
    return recurse(s, count_refs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 218, in _walk
    schema = self._schema_type_to_method[schema['type']](schema, f)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 323, in handle_union_schema
    new_choices.append(self.walk(v, f))
                       ^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 215, in walk
    return f(schema, self._walk)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/workzilla-tg-bot/.venv/lib/python3.11/site-packages/pydantic/_internal/_core_utils.py", line 515, in count_refs
    recurse(state['definitions'][ref], count_refs)
            ~~~~~~~~~~~~~~~~~~~~^^^^^
KeyError: 'aiogram.types.input_text_message_content.InputTextMessageContent:32048144'

Additional information

Also tested on Ubuntu 22.04 with python 3.9/3.10/3.11. Same error.
To solve this error you just need to downgrade pydantic version from 2.4.0 to 2.3.0.

@diprog diprog added the bug Something is wrong with the framework label Sep 25, 2023
@foozzi
Copy link

foozzi commented Sep 25, 2023

same error
this is a problem with the last pydantic update

who has this problem in their project, just pydantic==2.3.0 in your requirements.txt

@Olegt0rr
Copy link
Contributor

Olegt0rr commented Sep 25, 2023

Caused by breaking pydantic update: pydantic/pydantic#7523

Fixed in aiogram==3.1.1 (#1322)

@Olegt0rr Olegt0rr pinned this issue Sep 25, 2023
@JrooTJunior JrooTJunior unpinned this issue Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is wrong with the framework
Projects
None yet
Development

No branches or pull requests

3 participants