Skip to content

fix: mutable default set argument in wait_for_job_status (#329)#393

Open
Adithya-S-01 wants to merge 1 commit intokubeflow:mainfrom
Adithya-S-01:fix/mutable-default-set-329
Open

fix: mutable default set argument in wait_for_job_status (#329)#393
Adithya-S-01 wants to merge 1 commit intokubeflow:mainfrom
Adithya-S-01:fix/mutable-default-set-329

Conversation

@Adithya-S-01
Copy link

@Adithya-S-01 Adithya-S-01 commented Mar 17, 2026

Fixes #329

Description
This PR resolves the mutable default argument anti-pattern present in the wait_for_job_status methods across the Trainer and Optimizer APIs. Previously, these methods defined status: set[str] = {constants.TRAINJOB_COMPLETE}, which initializes the set object exactly once when the module is evaluated by the Python interpreter.

Because sets are mutable, this pattern causes the exact same set instance to be shared across all subsequent invocations of wait_for_job_status within the same process. If any subclass or client code were to mutate this argument during execution, it would cause side effects across parallel or future SDK calls, leading to unpredictable job polling behavior.

  • Updated the method signatures in 8 files across kubeflow/trainer and kubeflow/optimizer client APIs and backends (LocalProcess, Kubernetes, Container) to use status: set[str] | None = None.
  • Shifted the default set instantiation into the function bodies using if status is None: status = {constants.*} to guarantee a fresh, isolated set per invocation.
  • Removed unused kubeflow.optimizer.constants.constants imports from optimizer_client.py and optimizer/backends/base.py that were orphaned by removing the constants from the method signatures.
  • Verified changes via the existing make test-python suite to ensure test coverage, alongside uv run ruff check and uv run ty check inside make verify for strict type and format compliance.

Copilot AI review requested due to automatic review settings March 17, 2026 18:15
@google-oss-prow
Copy link
Contributor

[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 astefanutti 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

@github-actions
Copy link
Contributor

🎉 Welcome to the Kubeflow SDK! 🎉

Thanks for opening your first PR! We're happy to have you as part of our community 🚀

Here's what happens next:

  • If you haven't already, please check out our Contributing Guide for repo-specific guidelines and the Kubeflow Contributor Guide for general community standards
  • Our team will review your PR soon! cc @kubeflow/kubeflow-sdk-team

Join the community:

Feel free to ask questions in the comments if you need any help or clarification!
Thanks again for contributing to Kubeflow! 🙏

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes mutable default set arguments from wait_for_job_status APIs across Trainer and Optimizer backends/clients, replacing them with None defaults and initializing to the appropriate “complete” status inside implementations.

Changes:

  • Update wait_for_job_status signatures to use status: set[str] | None = None instead of a mutable default set.
  • Initialize default status sets inside backend implementations (TRAINJOB_COMPLETE / OPTIMIZATION_JOB_COMPLETE).
  • Remove now-unneeded constants imports where they were only used for the previous default argument.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
kubeflow/trainer/backends/localprocess/backend.py Avoid mutable default by defaulting status to None and initializing to TRAINJOB_COMPLETE.
kubeflow/trainer/backends/kubernetes/backend.py Same change for Kubernetes trainer backend, preserving validation and behavior.
kubeflow/trainer/backends/container/backend.py Same change for container trainer backend, preserving behavior.
kubeflow/trainer/backends/base.py Update abstract backend API signature to accept status=None.
kubeflow/trainer/api/trainer_client.py Update client API signature to accept status=None and forward it.
kubeflow/optimizer/backends/kubernetes/backend.py Avoid mutable default by initializing status to OPTIMIZATION_JOB_COMPLETE when None.
kubeflow/optimizer/backends/base.py Update abstract optimizer backend API signature and remove unused constants import.
kubeflow/optimizer/api/optimizer_client.py Update client API signature and remove unused constants import.

@Adithya-S-01 Adithya-S-01 changed the title Fix mutable default set argument in wait_for_job_status (Issue #329) fix: mutable default set argument in wait_for_job_status (#329) Mar 17, 2026
Signed-off-by: Adithya <unknown0101200111@gmail.com>
@Adithya-S-01 Adithya-S-01 force-pushed the fix/mutable-default-set-329 branch from 3bb31f5 to 44f10f3 Compare March 17, 2026 18:25
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:Mutable Default Set Argument

2 participants