Closed VictorGoubet closed 3 weeks ago
Hi @VictorGoubet, thank you for the detailed bug report! I'll try to reproduce the issue locally (but this looks legit already).
Thanks again @VictorGoubet, I've applied your suggestion :slightly_smiling_face:
Description of the bug
In the jinja template, in the config section we iterate throught each key value of the config griffe object and we highlight the value. However the
highlight
method take a string as input and it will fail if another kind of value is took as input.Here is the targeted peace of code:
Now comes the issue, if you are using
pydantic
> 2.0 you will probably use the new way to define the config withmodel_dict
being aConfigDict
. When you switch from the old config definition (withclass Config
) to the new here is the change in thedata.extra.griffe_pydantic
:With
class Config
definition:With
ConfigDict
definition:In the first case you can see that there is no section about config, but in the second one there is a section about config. So in the first case the
{% if class.extra.griffe_pydantic.config %}
condition is not met so no issue, but with newer pydantic version the config now exist and looks like this:So here we see that it mapped strings to
ExprDict
, andhighlight
method does not like to getExprDict
as input which finally raise our error:To Reproduce
Inorder to reproduce you can try to display this pydantic model:
Full traceback
Expected behavior
The expected behavior is to not fail even if some values of the config are not dict and to convert it before in string. Moreover the
model_config
field should not be displayed since it's now a special field dedicated to the config that will already be displayed.Here is the suggestion:
Environment information
python: 3.10.12
Libs:
Tell me what you think about, I can do a PR to implement the changes if needed