-
Notifications
You must be signed in to change notification settings - Fork 1
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
Update Pydantic to version 2.4.2 #10
Conversation
@model_validator(mode="after") | ||
def validate_directives(self) -> ReportData: |
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.
Using the model_validator
with mode before
would allow us to get the values as a dictionary, similar to what was happening with the deprecated root_validator
. However, it seems like using before
with the model_validator
ignores the field's alias
parameter, which means that if users are passing effective-directive
, that's what we get on the values dictionary.
I'm not sure if this Pydantic change was intentional or not, since before
validators are supposed to validate before any parsing is done on the fields, but it seems to me like we should be able to access the original field by the field's name, not its alias.
raise ValueError( | ||
"Either 'effective_directive' or 'violated_directive' must be present." | ||
) | ||
|
||
class Config: | ||
allow_population_by_field_name = True | ||
model_config = ConfigDict(populate_by_name=True, coerce_numbers_to_str=True) |
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.
coerce_numbers_to_str=True
was added to allow status_code
to be an integer or a string, which was the behaviour before this change.
This is because Pydantic 1.x.x would coerce numbers to strings by default, whereas Pydantic 2.x.x will not do this by default.
I'm not sure if we want to keep this behaviour or not though.
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.
I've added a suggestion on the tox support (which may have implications for GH actions).
6ffa4ea
to
13d70c4
Compare
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.
LGTM - although I'm largely commenting on the version upgrade itself, not on the changes made to decorators.
Upgrades
Pydantic
to version2.4.2
and updates the code accordingly.Closes #9