Fix Pydantic model_fields instance access deprecation warnings (#9278)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Graham Neubig 2025-06-23 14:54:13 -04:00 committed by GitHub
parent 6aad23d35c
commit 5e5168ffd4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View File

@ -51,7 +51,7 @@ def get_field_info(field: FieldInfo) -> dict[str, Any]:
def model_defaults_to_dict(model: BaseModel) -> dict[str, Any]:
"""Serialize field information in a dict for the frontend, including type hints, defaults, and whether it's optional."""
result = {}
for name, field in model.model_fields.items():
for name, field in model.__class__.model_fields.items():
field_value = getattr(model, name)
if isinstance(field_value, BaseModel):

View File

@ -67,7 +67,7 @@ def load_from_env(
# helper function to set attributes based on env vars
def set_attr_from_env(sub_config: BaseModel, prefix: str = '') -> None:
"""Set attributes of a config model based on environment variables."""
for field_name, field_info in sub_config.model_fields.items():
for field_name, field_info in sub_config.__class__.model_fields.items():
field_value = getattr(sub_config, field_name)
field_type = field_info.annotation