🐛 Fix extracting attributes for old Pydantic versions

This commit is contained in:
Sebastián Ramírez 2025-12-12 15:08:49 +01:00
parent 1643b0b6f5
commit f75daed0a0
1 changed files with 6 additions and 1 deletions

View File

@ -78,10 +78,15 @@ _Attrs = {
# TODO: remove when dropping support for Pydantic < v2.12.3
def asdict(field_info: FieldInfo) -> Dict[str, Any]:
attributes = {}
for attr in _Attrs:
value = getattr(field_info, attr, Undefined)
if value is not Undefined:
attributes[attr] = value
return {
"annotation": field_info.annotation,
"metadata": field_info.metadata,
"attributes": {attr: getattr(field_info, attr) for attr in _Attrs},
"attributes": attributes,
}