Closed caseyzak24 closed 1 month ago
This seems to have been solved with the following package upgrades/versions:
sphinx 8.1.3 pydantic 2.9.2 autodoc-pydantic 2.2.0 sphinx-rtd-theme 3.0.1 sphinx-autodoc-typehints 2.5.0
Unfortunately I'm not exactly sure which of these upgrades or additional package installs resolved the issue. I performed them trying to solve a different problem and after doing so checked to see if they resolved this problem and they did. Hopefully this will help others facing a similar issue.
Build Versions
sphinx 7.4.7 pydantic 2.9.2 autodoc-pydantic 2.2.0
Problem
We recently migrated to v2 for pydantic/autodoc_pydantic and the html build now fails with
The full traceback wasn't much more help, so I modified the
_get_meta_items
method in inspection.py as follows:which revealed that the failure occurs on the field type constraint, which is coming up as string instead of a metaclass instance. This seems to be because we use Annotated types for fields as clean way to document field units in our code and docs. To demonstrate:
unit_types.py
conf.py
models.py
Using pydantic/autodoc-pydantic v1, this would generate docs like this:
Given that
autodoc_type_aliases
is a sphinx autodoc feature and this worked for v1, I assume previously autodoc-pydantic either handed this to sphinx to resolve or just ignored it and let autodoc handle it after (I'm a little unclear on the handling order).Happy to work on fixing this if I'm pointed in the right direction, or perhaps our approach is just hacky and there is a more canonical way to achieve the same result in v2.