mansenfranzen / autodoc_pydantic

Seamlessly integrate pydantic models in your Sphinx documentation.
MIT License
159 stars 27 forks source link

Build failure with Enum under Pydantic 2.1, autodoc-pydantic 2.0.0 #169

Closed nagledb closed 1 year ago

nagledb commented 1 year ago

I am receiving doc build failures when trying to use an enum in a pydantic model.

Repo:

  1. Copy the code fragment from https://docs.pydantic.dev/latest/usage/types/enums/:
    
    from enum import Enum, IntEnum

from pydantic import BaseModel, ValidationError

class FruitEnum(str, Enum): pear = 'pear' banana = 'banana'

class ToolEnum(IntEnum): spanner = 1 wrench = 2

class CookingModel(BaseModel): fruit: FruitEnum = FruitEnum.pear tool: ToolEnum = ToolEnum.spanner

2. Include `.. autopydantic_model:: mymodule.CookingModel` in your RST file.
3. Build the docs.

Exception occurred: File "/Users/nagledb/Library/Caches/pypoetry/virtualenvs/myproject-B9PtQW94-py3.8/lib/python3.8/site-packages/sphinxcontrib/autodoc_pydantic/inspection.py", line 195, in get_given_constraint_keys field_schemas = definition["schema"]["schema"]["fields"] KeyError: 'schema' The full traceback has been saved in /var/folders/kf/kxls27sn2_qcslc3nhgrg7j40000gq/T/sphinx-err-fv0oyxyr.log, if you want to report the issue to the developers. Please also report this if it was a user error, so that a better error message can be provided next time. A bug report can be filed in the tracker at https://github.com/sphinx-doc/sphinx/issues. Thanks! make: *** [html] Error 2

Full log is here: [sphinx-err-fv0oyxyr.log](https://github.com/mansenfranzen/autodoc_pydantic/files/12176777/sphinx-err-fv0oyxyr.log)

I am running python 3.8.16. Some of my relevant package versions:

autodoc-pydantic==2.0.0 pydantic==2.1.0 pydantic-settings==2.0.2 pydantic_core==2.4.0 Sphinx==5.1.1 sphinxcontrib-applehelp==1.0.4 sphinxcontrib-devhelp==1.0.2 sphinxcontrib-htmlhelp==2.0.1 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.5

mansenfranzen commented 1 year ago

@nagledb Thanks for raising this issue here! I can confirm, this is definitely a bug. This part of the code adjustments for pydantic v2 is actually the most shaky part, too. Hence, it is great to spot this bug early on.

Thanks to @jerryjiahaha who already provided a PR via #170 fixing the bug :-).

Expect this bug to be fixed within the next days.

mansenfranzen commented 1 year ago

@all-contributors please add @nagledb for bug

allcontributors[bot] commented 1 year ago

@mansenfranzen

I've put up a pull request to add @nagledb! :tada:

mansenfranzen commented 1 year ago

@all-contributors please add @jerryjiahaha for code

allcontributors[bot] commented 1 year ago

@mansenfranzen

I've put up a pull request to add @jerryjiahaha! :tada:

mansenfranzen commented 1 year ago

Bug is fixed a new version v2.0.1 can be installed via pip install "autodoc_pydantic>=2.0.1,<3.0".