fix(sdk): resolve kfp.dsl.pipeline_context circular import. Fixes #12522 - #13997
fix(sdk): resolve kfp.dsl.pipeline_context circular import. Fixes #12522#13997shivv23 wants to merge 1 commit into
Conversation
…eflow#12522 Signed-off-by: shivv23 <shivamkumar0423@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @shivv23. Thanks for your PR. I'm waiting for a kubeflow member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Description of your changes:
Fixes #12522.
Under
_KFP_RUNTIME=true(e.g., when the Kubeflow Pipelines runtime or Vertex AI executes a pipeline function), importingkfp.dsl.graph_componentorkfp.dsl.pipeline_contextraised:The failure was caused by a circular import between the
kfp.dslpackage and thekfp.compilerpackage:graph_component.pyimportedkfp.compiler.pipeline_spec_builderat module import time, which pulls inkfp.compiler.compiler_utils, which importskfp.dsl.pipeline_context, which importskfp.dsl.component_factory, which importskfp.dsl.graph_component(still partially initialized), and an eagerly evaluated return annotation (-> graph_component.GraphComponent) crashed._validate_workspace_requirementswith an eagerly evaluatedpipeline: pipeline_context.Pipelineparameter annotation ingraph_component.py.Changes:
sdk/python/kfp/dsl/graph_component.py: importkfp.compiler.pipeline_spec_builderlazily inside__init__instead of at module import time, breaking the circular import at its source; addfrom __future__ import annotationsto defer annotation evaluation.sdk/python/kfp/dsl/component_factory.py: addfrom __future__ import annotationsso the-> graph_component.GraphComponentreturn annotation is no longer evaluated eagerly.sdk/python/kfp/dsl/base_component.py: importpipeline_contextlazily inside__call__(its only use), removing thebase_component -> pipeline_context -> component_factory -> container_component_class/python_component -> base_componentcycle from the DSL-internal import graph.sdk/python/kfp/dsl/graph_component_test.py: new regression test that importskfp.dsl.graph_componentandkfp.dsl.pipeline_contextin subprocesses with_KFP_RUNTIME=true.Checklist: