You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
python Python 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:38:13) [GCC 12.3.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> from model import TestTraceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/jovyan/xlsxdatagrid/tests/model.py", line 19, in <module> class Test(BaseModel): File "/home/jovyan/miniforge3/envs/xlsxdatagrid-dev/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 197, in __new__ set_model_fields(cls, bases, config_wrapper, types_namespace) File "/home/jovyan/miniforge3/envs/xlsxdatagrid-dev/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 474, in set_model_fields fields, class_vars = collect_model_fields(cls, bases, config_wrapper, types_namespace, typevars_map=typevars_map) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jovyan/miniforge3/envs/xlsxdatagrid-dev/lib/python3.12/site-packages/pydantic/_internal/_fields.py", line 229, in collect_model_fields field_info = FieldInfo.from_annotated_attribute(ann_type, default) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jovyan/miniforge3/envs/xlsxdatagrid-dev/lib/python3.12/site-packages/pydantic/fields.py", line 351, in from_annotated_attribute raise PydanticUserError(pydantic.errors.PydanticUserError: Error when building FieldInfo from annotated attribute. Make sure you don't have any field name clashing with a type annotation For further information visit https://errors.pydantic.dev/2.7/u/unevaluable-type-annotation>>>
Expected behavior
The issue seems to be because of the name and field name overlap of DEnum.
It would be great if it was smart enough not to let that happen... or else allow the user an argument to append some text onto Enum names or add a variable to the jsonschema that sets the enum name.
Version:
OS: [e.g. iOS] Ubuntu2204
Python version: 3.12.3
datamodel-code-generator version: 0.25.6
Additional context
If you can suggest workarounds that would also be appreciated
Aside
the default value also doesn't appear to be coming through
The text was updated successfully, but these errors were encountered:
Describe the bug
generated pydantic code is faulty when the field name matches the generated enum name for a given field.
To Reproduce
Example schema:
Used commandline:
generates
model.py
:then when try to use this file you get an error:
Expected behavior
The issue seems to be because of the name and field name overlap of DEnum.
It would be great if it was smart enough not to let that happen... or else allow the user an argument to append some text onto Enum names or add a variable to the jsonschema that sets the enum name.
Version:
Additional context
If you can suggest workarounds that would also be appreciated
Aside
the default value also doesn't appear to be coming through
The text was updated successfully, but these errors were encountered: