Add support for custom flow decorators to prefect deploy
#14782
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR alters how the client loads a flow from source code when dependencies are missing. Previously, the client would attempt to retrieve flow metadata from the @flow decorator and generate a parameter schema for the decorated function by traversing the abstract syntax tree (AST). This approach prevents the use of custom decorators that wrap the @flow decorator.
This PR instead adds a safe_load_flow_from_entrypoint function which is capable of loading the full flow after making modifications to the AST. safe_load_flow_from_entrypoint will use safe_load_namespace to avoid raising exceptions when dependencies are not present on the current machine when loading a flow. If the flow depends on types or objects from missing dependencies, the AST will be updated to remove the annotations, causing loading to fail. This can generate a different parameter schema if the necessary dependencies are present or not.
safe_load_flow_from_entrypoint is used as a fallback within load_flow_from_entrypoint, so the behavior should not be altered in most cases.
I recognize this implementation is complex and understand this PR might be rejected. If it is accepted, or you decide to go an alternative route without AST parsing, much of the old AST parsing implementation can be deprecated and/or removed in subsequent PRs.
Changes for this PR were originally introduced to
main
in #14694.Checklist
<link to issue>
"mint.json
.