-
Notifications
You must be signed in to change notification settings - Fork 106
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
Add support for pydantic v2 #795
Conversation
Sorry for the large PR w/o much prior discussion - I think a lot of it is pretty rote transformations though (updating imports). This one might also be a bit easier to review commit-by-commit. |
hey @JacobHayes bit of a driveby comment but i'd done a little digging as well into introducing pydantic v2 compatibility here and ran into the exact issues with the |
Much appreciated @matty-rose! |
39388ea
to
8ddabf3
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #795 +/- ##
=====================================
Coverage 79.7% 79.7%
=====================================
Files 45 45
Lines 3706 3724 +18
Branches 750 754 +4
=====================================
+ Hits 2955 2970 +15
- Misses 558 560 +2
- Partials 193 194 +1 ☔ View full report in Codecov by Sentry. |
ed785c6
to
08bcfec
Compare
I'd still like to add a test run that overrides the Do you all have any suggestions? Perhaps adding a simplified |
This sounds great to me. Could it be included in the matrix build maybe? |
Are you thinking a new One thing I'm not certain about is whether |
Yea, that's what I was thinking! And also this would be temporary. Perhaps we can remove it in a few months.
Hopeful that we don't have to change it :) |
@samj1912 and @elliotgunton this PR + approach LGTM. Any chance I can trouble you to review? Also weigh in on the Q of pydantic V1 vs V2 testing |
08bcfec
to
bc5ac35
Compare
Going to work on adding pydantic versions to build matrix here in a bit |
@elliotgunton and @samj1912 nudge to review this. Again, LGTM, and I am a fan of the second job approach to verify pydantic v1 backwards compatibility |
@JacobHayes what do you think about appending [mypy-pydantic.*]
ignore_missing_imports = True to |
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.
Awesome stuff @JacobHayes! 🚀
On this:
add a couple more tests and try to support serializing v1 and v2 user-defined models (not just the v1 models from either version - I think this should be possible).
Have you been able to add v2 models? I think a couple of tests using v2 models mirroring the callable_script.py
example would suffice!
Thanks for the suggestions, circling back to this today. 🚀 I think we should be able to get v1 and v2 user models serialized, but I think it'd be best (or at least easiest 😁) for the Hera internal models to be "all v1" or "all v2" until we move to v2 only. |
ee2480d
to
fcdd964
Compare
rebased, but will follow up on the rest tomorrow |
Signed-off-by: Jacob Hayes <jacob.r.hayes@gmail.com>
Signed-off-by: Jacob Hayes <jacob.r.hayes@gmail.com>
36a504f
to
70e7a9e
Compare
Signed-off-by: Matt Rose <mattyrose@canva.com>
Signed-off-by: Jacob Hayes <jacob.r.hayes@gmail.com>
Signed-off-by: Jacob Hayes <jacob.r.hayes@gmail.com>
Signed-off-by: Jacob Hayes <jacob.r.hayes@gmail.com>
Signed-off-by: Jacob Hayes <jacob.r.hayes@gmail.com>
Signed-off-by: Sambhav Kothari <skothari44@bloomberg.net>
70e7a9e
to
71a4557
Compare
@@ -89,7 +91,7 @@ def function_kebab_object(annotated_input_value: Annotated[Input, Parameter(name | |||
with Workflow(name="my-workflow") as w: | |||
with Steps(name="my-steps") as s: | |||
my_function(arguments={"input": Input(a=2, b="bar", c=42)}) | |||
str_function(arguments={"input": Input(a=2, b="bar", c=42).json()}) | |||
str_function(arguments={"input": serialize(Input(a=2, b="bar", c=42))}) |
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.
This needs to be changed to serialize
function in hera, which correctly handles dumping both v1 and v2 objects.
pytest.param( | ||
"tests.script_runner.parameter_inputs:str_subclass_parameter_expects_jsonstr_dict", | ||
[{"name": "my_json_str", "value": json.dumps({"my": "dict"})}], | ||
{"my": "dict"}, | ||
id="str-subclass-json-param-as-dict", | ||
), | ||
pytest.param( | ||
"tests.script_runner.parameter_inputs:str_subclass_annotated_parameter_expects_jsonstr_dict", | ||
[{"name": "my_json_str", "value": json.dumps({"my": "dict"})}], | ||
{"my": "dict"}, | ||
id="str-subclass-json-annotated-param-as-dict", | ||
), |
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.
Had to remove these tests as MyStr
is considered an arbitrary type in pydantic v2 and we don't have arbitrary types enabled even for v1. Made more sense to just get rid of this example (which we had added of our own volition in a recent PR by @elliotgunton )
Signed-off-by: Sambhav Kothari <skothari44@bloomberg.net>
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.
Nothing blocking, looking good 🚀
685aaa5
to
6c22fb1
Compare
Signed-off-by: Sambhav Kothari <skothari44@bloomberg.net>
6c22fb1
to
2b8ed33
Compare
This would have (or could 😁) simplify mypy things across versions: pydantic/pydantic#9042 |
Pull Request Checklist
Description of PR
WIP, but wanted to get the bulk of it up for any feedback while I:
This PR updates hera to support use with either pydantic v1 or v2 installed. All hera internal code now imports pydantic objects from
hera.shared._pydantic
(extended and renamed from_base_model
). This module ensures that we're always using v1 compatible objects, which allows us to support codebases installing either pydantic v1 or v2 (although the models passed to Hera must be v1 for pydantic v1 and v2 for pydantic v2).