Skip to content

bug: Cannot import mkdocstrings-python>=1.14.0 if Pydantic v1 is installed #240

Closed

Description

@jvstme

Description of the bug

Our project uses Pydantic v1 and our docs stopped building after mkdocstrings-python 1.14.0 was released. It seems that importing mkdocstrings_handlers.python doesn't work if Pydantic v1 is installed.

To Reproduce

> pip install "pydantic<2.0.0" mkdocstrings-python==1.14.1
> python -c "import mkdocstrings_handlers.python"

Full traceback

Full traceback
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import mkdocstrings_handlers.python
  File "/tmp/venv/lib64/python3.13/site-packages/mkdocstrings_handlers/python/__init__.py", line 3, in <module>
    from mkdocstrings_handlers.python.handler import get_handler
  File "/tmp/venv/lib64/python3.13/site-packages/mkdocstrings_handlers/python/handler.py", line 30, in <module>
    from mkdocstrings_handlers.python.config import PythonConfig, PythonOptions
  File "/tmp/venv/lib64/python3.13/site-packages/mkdocstrings_handlers/python/config.py", line 71, in <module>
    @dataclass(**_dataclass_options)  # type: ignore[call-overload]
     ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "pydantic/dataclasses.py", line 231, in pydantic.dataclasses.dataclass.wrap
  File "pydantic/dataclasses.py", line 354, in pydantic.dataclasses._add_pydantic_validation_attributes
  File "pydantic/dataclasses.py", line 407, in pydantic.dataclasses.create_pydantic_model_from_dataclass
  File "pydantic/main.py", line 1030, in pydantic.main.create_model
  File "pydantic/main.py", line 197, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 495, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 474, in pydantic.fields.ModelField._get_field_info
ValueError: cannot specify `Annotated` and value `Field`s together for 'ignore_init_summary'

Expected behavior

It would be great if mkdocstrings-python could support Pydantic v1 or at least ignore it, since the Pydantic dependency seems to be optional anyway.

Activity

  1. added
    unconfirmed
    on Feb 3, 2025
  2. pawamoy commented on Feb 3, 2025

    @pawamoy
    Member

    Hi @jvstme, thanks for the fast report, and sorry for the inconvenience. I remember thinking this could cause issues, but had to forget about it 😵‍💫 Let me push a fix that checks Pydantic's version to deactivate the logic if it's v1.

  3. pawamoy commented on Feb 3, 2025

    @pawamoy
    Member

    Should be fixed in v1.14.2, let me know 🤞

  4. added
    bug
    and removed
    unconfirmed
    on Feb 3, 2025
  5. jvstme commented on Feb 3, 2025

    @jvstme
    Author

    @pawamoy, yes, 1.14.2 works for us. Thanks for the prompt resolution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions