Skip to content
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

Refining how we validate flow parameters under Pydantic 1 versus 2 #11028

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

chrisguidry
Copy link
Collaborator

We have seen a few edge cases popping up where we're trying to use the
pydantic v2 validator to validate v1 models as flow function arguments. This
leads to the opaque error:

TypeError: BaseModel.validate() takes 2 positional arguments but 3 were given

Examples:

The issue here is that we were trying to use our custom v2 port of the v1
ValidatedFunction, without inspecting the types of models involved. Here, we
are looking at the types of the passed arguments, validating that they aren't
mixing v1 and v2 models, and then choosing the right validation implementation
from there.

We have seen a few edge cases popping up where we're trying to use the
pydantic v2 validator to validate v1 models as flow function arguments.  This
leads to the opaque error:

```
TypeError: BaseModel.validate() takes 2 positional arguments but 3 were given
```

Examples:
* PrefectHQ/prefect-airbyte#61
* https://github.com/PrefectHQ/prefect-kubernetes/actions/runs/6628004996/job/18004160832?pr=92

The issue here is that we were trying to use our custom v2 port of the v1
`ValidatedFunction`, without inspecting the types of models involved.  Here, we
are looking at the types of the passed arguments, validating that they aren't
mixing v1 and v2 models, and then choosing the right validation implementation
from there.
@chrisguidry chrisguidry requested a review from a team as a code owner October 25, 2023 19:23
@netlify
Copy link

netlify bot commented Oct 25, 2023

Deploy Preview for prefect-docs-preview ready!

Name Link
🔨 Latest commit cbe3380
🔍 Latest deploy log https://app.netlify.com/sites/prefect-docs-preview/deploys/65396b29743e690008e396a3
😎 Deploy Preview https://deploy-preview-11028--prefect-docs-preview.netlify.app/api-ref/prefect/flows
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@urimandujano urimandujano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this boils down to our downstream lib using pydantic's v1 compat module and us expecting a v2 model (since we detect v2 is installed).

This looks extremely useful!

@chrisguidry
Copy link
Collaborator Author

Yep I think this is popping up in our collections libraries because they have flows that are passing blocks around as parameters, and the blocks are ultimately derived from v1 base models (for now).

@chrisguidry
Copy link
Collaborator Author

FWIW, I also tested this with an editable local install in our prefect-kubernetes collection and it resolved the problems with the test suite there.

@chrisguidry chrisguidry merged commit 6858612 into main Oct 25, 2023
49 checks passed
@chrisguidry chrisguidry deleted the pydantic-v1-vs-v2-validated-functions branch October 25, 2023 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants