Skip to content

fix(sdk): resolve kfp.dsl.pipeline_context circular import. Fixes #12522 - #13997

Open
shivv23 wants to merge 1 commit into
kubeflow:masterfrom
shivv23:fix/12522-pipeline-context-circular-import
Open

fix(sdk): resolve kfp.dsl.pipeline_context circular import. Fixes #12522#13997
shivv23 wants to merge 1 commit into
kubeflow:masterfrom
shivv23:fix/12522-pipeline-context-circular-import

Conversation

@shivv23

@shivv23 shivv23 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Description of your changes:

Fixes #12522.

Under _KFP_RUNTIME=true (e.g., when the Kubeflow Pipelines runtime or Vertex AI executes a pipeline function), importing kfp.dsl.graph_component or kfp.dsl.pipeline_context raised:

AttributeError: partially initialized module 'kfp.dsl.pipeline_context' has no attribute 'Pipeline' (most likely due to a circular import)

The failure was caused by a circular import between the kfp.dsl package and the kfp.compiler package:

  • graph_component.py imported kfp.compiler.pipeline_spec_builder at module import time, which pulls in kfp.compiler.compiler_utils, which imports kfp.dsl.pipeline_context, which imports kfp.dsl.component_factory, which imports kfp.dsl.graph_component (still partially initialized), and an eagerly evaluated return annotation (-> graph_component.GraphComponent) crashed.
  • The regression was introduced by feat(sdk): add compile-time validation for workspace size #12234, which added _validate_workspace_requirements with an eagerly evaluated pipeline: pipeline_context.Pipeline parameter annotation in graph_component.py.

Changes:

  • sdk/python/kfp/dsl/graph_component.py: import kfp.compiler.pipeline_spec_builder lazily inside __init__ instead of at module import time, breaking the circular import at its source; add from __future__ import annotations to defer annotation evaluation.
  • sdk/python/kfp/dsl/component_factory.py: add from __future__ import annotations so the -> graph_component.GraphComponent return annotation is no longer evaluated eagerly.
  • sdk/python/kfp/dsl/base_component.py: import pipeline_context lazily inside __call__ (its only use), removing the base_component -> pipeline_context -> component_factory -> container_component_class/python_component -> base_component cycle from the DSL-internal import graph.
  • sdk/python/kfp/dsl/graph_component_test.py: new regression test that imports kfp.dsl.graph_component and kfp.dsl.pipeline_context in subprocesses with _KFP_RUNTIME=true.

Checklist:

@google-oss-prow
google-oss-prow Bot requested review from nsingla and zazulam August 8, 2026 13:07
@google-oss-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign chensun for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow

Copy link
Copy Markdown

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[backend] Strange Behavior After 2.15.1 released

1 participant