fix(hidden_params): read private attributes only off a real pydantic class

A spec'd test double passes isinstance(obj, BaseModel) through __class__ while its type has no __private_attributes__, which raised on every hidden params read

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
kerry 2026-10-28 02:28:17 +00:00
parent b6571348e5
commit e2033586a4

View file

@ -63,7 +63,8 @@ def stored_attribute(obj: object, name: str) -> object:
def _get_hidden_params_storage(obj: object) -> object | None:
if isinstance(obj, dict):
return obj.get(_HIDDEN_PARAMS_ATTR)
if isinstance(obj, BaseModel) and _HIDDEN_PARAMS_ATTR in type(obj).__private_attributes__:
model_type: Final = type(obj)
if issubclass(model_type, BaseModel) and _HIDDEN_PARAMS_ATTR in model_type.__private_attributes__:
return getattr(obj, _HIDDEN_PARAMS_ATTR, None)
return stored_attribute(obj, _HIDDEN_PARAMS_ATTR)