-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: access model fields via class #2146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Emmanuel Ferdman <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR addresses a Pydantic V2 deprecation warning by updating how model fields are accessed in the update_strings
utility function. The change modifies line 52 in ragas/src/ragas/prompt/utils.py
from new_obj.model_fields
to new_obj.__class__.model_fields
, switching from the deprecated instance-based field access to the recommended class-based approach.
This fix aligns with Pydantic V2.11+ API requirements, where accessing model_fields
directly on instances has been deprecated in favor of accessing it through the model class. The update_strings
function appears to be a utility that recursively processes Pydantic model fields to update string values, making proper field access essential for its operation.
The change is part of maintaining compatibility with evolving Pydantic versions, as the deprecated functionality will be completely removed in Pydantic V3.0. This update ensures the codebase remains future-proof while eliminating warning noise from CI builds.
Confidence score: 5/5
- This is an extremely safe change that simply updates deprecated API usage to the current standard
- High confidence because it's a direct API migration with no functional changes, addressing a clear deprecation warning
- No files need additional attention - this is a minimal, well-targeted fix
1 file reviewed, no comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @emmanuel-ferdman 🎉
However the type checks are failing. Could you please rebase and run make run-ci
locally once?
Thanks @emmanuel-ferdman |
## PR Summary This small PR updates the usage of field metadata access to align with the Pydantic V2 API and resolve Pydantic deprecation warnings, as seen in the [CI logs](https://github.com/explodinggradients/ragas/actions/runs/16534007312/job/46765109247#step:8:56): ```python PydanticDeprecatedSince211: Accessing the 'model_fields' attribute on the instance is deprecated. Instead, you should access this attribute from the model class. Deprecated in Pydantic V2.11 to be removed in V3.0. ``` Signed-off-by: Emmanuel Ferdman <[email protected]>
## PR Summary This small PR updates the usage of field metadata access to align with the Pydantic V2 API and resolve Pydantic deprecation warnings, as seen in the [CI logs](https://github.com/explodinggradients/ragas/actions/runs/16534007312/job/46765109247#step:8:56): ```python PydanticDeprecatedSince211: Accessing the 'model_fields' attribute on the instance is deprecated. Instead, you should access this attribute from the model class. Deprecated in Pydantic V2.11 to be removed in V3.0. ``` Signed-off-by: Emmanuel Ferdman <[email protected]>
PR Summary
This small PR updates the usage of field metadata access to align with the Pydantic V2 API and resolve Pydantic deprecation warnings, as seen in the CI logs: