-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Orqsdk 1042 support Pydantic v1 in addition to V2 (#373)
# The problem in #372 we bumped pydantic to V2. As raised by @jamesclark-Zapata, we have conflicts with Amazon bracket and it would be nice to let the user's pip do the final resolving. # This PR's solution Maintains pydantic V2-style syntax throughout our code. We encompass as much of the compatibility layer in [src/orquestra/sdk/_base/_storage/orqdantic.py](https://github.com/zapatacomputing/orquestra-workflow-sdk/blob/275ab19a8bebb5d70cc16698206f403dd012cbaa/src/orquestra/sdk/_base/_storage/orqdantic.py) as possible. This file provides the following: - Class `BaseModel` - used throughout our code in place of `pydantic.BaseModel`. - When V2 is installed this is a subclass of `pydantic.BaseModel` providing the `__setstate__` method [^1]. - When V1 is installed this is a subclass of `pydantic.GenericModel` that provides V2-style methods that serve as wrappers for the equivalent V1 methods - Class `TypeAdapter` - used throughout our code in place of `pydantic.TypeAdapter` - When V2 is installed this operates identically to `pydantic.TypeAdapter` - When V1 is installed this class acts as a translator between the V1-specific `parse_X_as` methods and the V2 TypeAdapter style syntax we use in our code. - Function `field_validator` - used throughout our code in place of `pydantic.field_validator` - When V2 is installed this operates identically to `pydantic.TypeAdapter` - When V1 is installed this operates as a wrapper for `pydantic.validator` and _tries_ to translate V2-style kwargs. There are not perfect analogues, so this is likely to cause problems if we add more validators. - `GpuResouceType` - The type used to define the `gpu` field of the `Resource` model. For V1 this is a simple `Optional[str]`. For V2, due to changes in how validators function, we need to annotate the type with a validator. [^1]: This was introduced in #372 to allow us to handle depickling objects pickled under pydantic V1. # Checklist _Check that this PR satisfies the following items:_ - [ ] Tests have been added for new features/changed behavior (if no new features have been added, check the box). - [x] The [changelog file](CHANGELOG.md) has been updated with a user-readable description of the changes (if the change isn't visible to the user in any way, check the box). - [x] The PR's title is prefixed with `<feat/fix/chore/imp[rovement]/int[ernal]/docs>[!]:` - [x] The PR is linked to a JIRA ticket (if there's no suitable ticket, check the box). [ORQSDK-1042] [ORQSDK-1042]: https://zapatacomputing.atlassian.net/browse/ORQSDK-1042?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: Alexander Juda <[email protected]> Co-authored-by: James Clark <[email protected]>
- Loading branch information
1 parent
5525102
commit c04317f
Showing
14 changed files
with
240 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.