Skip to content

fix(pipelines): don't duplicate the first node's decorator in the module header - #285

Open
sayaksatpathi wants to merge 4 commits into
kubeflow:mainfrom
sayaksatpathi:fix-python-ast-decorator-header
Open

sayaksatpathi wants to merge 4 commits into
kubeflow:mainfrom
sayaksatpathi:fix-python-ast-decorator-header

Conversation

@sayaksatpathi

Copy link
Copy Markdown

Summary

Fixes #284.

parse_python_ast computed the module_header boundary from the first node's def/class line (nodes[0].lineno). When that node is decorated, its own chunk starts at the decorator line, so the decorator line(s) were captured in both the header chunk and the function chunk — common for Kubeflow code using @dsl.component / @dsl.pipeline.

Fix

Use nodes[0].decorator_list[0].lineno as the header boundary when the first node is decorated. The decorator now belongs to the function chunk only.

Tests

Added test_decorated_first_node_not_duplicated_in_header to tests/test_code_utils.py. It fails on the current code (the header chunk ends with @dsl.component) and passes with this change. The existing parse_python_ast tests continue to pass and ruff check is clean.

…ule header

parse_python_ast set the module_header boundary at the first node's
def/class line (nodes[0].lineno). When that node is decorated, its own
chunk starts at the decorator line, so the decorator was captured in both
the header chunk and the function chunk -- common for Kubeflow code using
@dsl.component / @dsl.pipeline.

Use the decorator line as the header boundary when the first node has
decorators. Adds a regression test.

Signed-off-by: Sayak Satpathi <sayaksatpathi12@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 30, 2026 07:10
@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 tarekabouzeid 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@tarekabouzeid

Copy link
Copy Markdown
Member

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(pipelines): parse_python_ast duplicates the first node's decorator in the module_header chunk

3 participants