Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fix Pydantic model_fields instance access deprecation warnings (#9278)

Graham Neubig5e5168ffd4ec
diff --git a/openhands/core/config/config_utils.py b/openhands/core/config/config_utils.py
index 63f04ebd90..e8eb810672 100644
--- a/openhands/core/config/config_utils.py
+++ b/openhands/core/config/config_utils.py
@@ -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):
diff --git a/openhands/core/config/utils.py b/openhands/core/config/utils.py
index 9507226b19..876805869a 100644
--- a/openhands/core/config/utils.py
+++ b/openhands/core/config/utils.py
@@ -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