Repository navigation
fix(spark): replace mutable default set in wait_for_job_status - #887
Open
SAURABHSALVE wants to merge 1 commit into
Open
SAURABHSALVE wants to merge 1 commit into
SAURABHSALVE wants to merge 1 commit into
Conversation
status defaulted to a {SparkJobStatus.COMPLETED} set literal in
spark_client.py, backends/base.py, and backends/kubernetes/backend.py.
Python evaluates that literal once at function-definition time and
shares the same set object across every call that omits status, so an
in-place mutation of it (e.g. status.add(...)) would silently corrupt
the default target state for every later call, for the life of the
process.
Same anti-pattern as kubeflow#329, but kubeflow#330 and kubeflow#393 (both open) only touch
the Trainer and Optimizer modules, and kubeflow#874 only adds validation
inside the Spark wait_for_job_status body without touching the
default-argument line. None of them cover Spark.
Default to None and build a fresh {SparkJobStatus.COMPLETED} set
inside the function, matching the fix already used in kubeflow#330/kubeflow#393 for
the other modules.
Fixes kubeflow#885
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Saurabh Vijay Salve <saurabhsalve9999@gmail.com>
Contributor
|
[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 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this PR does / why we need it:
wait_for_job_statusin the Spark module still uses a mutable set literal as itsstatusdefault, in all three places that define it:kubeflow/spark/api/spark_client.py,kubeflow/spark/backends/base.py, andkubeflow/spark/backends/kubernetes/backend.py.This is the same anti-pattern reported in #329, but #330 and #393 (both currently open) only touch the Trainer and Optimizer modules — neither diff includes a single Spark file. #874 ("validate requested job statuses") edits these same three Spark files but only adds validation inside the function body; it doesn't touch the default-argument line either, so the mutable default survives that change too. This PR closes that gap for Spark.
Repro (see #885 for the full write-up): the default set object is created once and shared by every call that omits
status. If any code mutates it in place (e.g. extends it withstatus.add(...)instead of copying first), every later call made without an explicitstatusargument silently picks up the mutated set for the rest of the process's lifetime.Fix: default to
Nonein all three signatures, and build a fresh{SparkJobStatus.COMPLETED}set insidespark_client.pyandbackends/kubernetes/backend.pywhenstatus is None— matching the fix pattern already used in #330/#393 for the other modules.Verification
spark_client_test.py(signature-default check, and a behavioral test that mutates the set returned to one call and asserts the next default-using call is unaffected) and one inbackend_test.py(signature-default check).mainfor the right reason (status.default is {SparkJobStatus.COMPLETED}instead ofNone; the mutation leaks into the second call).pytest kubeflow/spark/api/spark_client_test.py kubeflow/spark/backends/kubernetes/backend_test.py→ 127 passed.ruff check,ruff format --check, andty check kubeflow/sparkon the changed files show no new issues (the 60 pre-existingtydiagnostics in this module are all in unrelated files/lines and present onmaintoo).Which issue(s) this PR fixes:
Fixes #885
Checklist:
{SparkJobStatus.COMPLETED}) is unchanged.🤖 Generated with Claude Code