kubeflow / kubeflow/sdk

bug: TypeError: 'NoneType' object is not iterable in LocalProcess backend when iterating over steps

Open
#569 2 comments 0 reactions 1 assignee Claimed by @NaveenKumarG-dev View on GitHub
kind/bug needs-triage
Dominant language
Python
Stars
148
Forks
262
Avg merge
1d 2h
Merged PRs (30d)
1

Description

### What happened?

When calling methods like `get_job_logs()` or deleting a job in the `LocalProcess` backend (`kubeflow.trainer.backends.localprocess.backend.LocalProcessBackend`), the code directly iterates over `_job[0].steps` (e.g. `for _step in _job[0].steps:`) without checking if it is `None`.

In `kubeflow/trainer/backends/localprocess/types.py`, the `steps` field is typed as `list[LocalBackendStep] | None = []`. If it is ever passed as `None` instead of an empty list, this results in a `TypeError: 'NoneType' object is not iterable`, crashing the process. (Note: This is currently being caught and reported by `uv run ty check` as well).

**Reproduction Steps**

```python
# Minimal reproduction example
from kubeflow.trainer.backends.localprocess.types import LocalBackendJobs
from kubeflow.trainer.backends.localprocess.backend import LocalProcessBackend

# Job with None steps
job = LocalBackendJobs(name="my-job", runtime=None, steps=None)

backend = LocalProcessBackend()
# Force inject the job for demonstration
backend._LocalProcessBackend__local_jobs = [job]

# This will crash with TypeError: 'NoneType' object is not iterable
backend.get_job_logs(name="my-job")

### What did you expect to happen?

The code should gracefully handle the `None` case in all iterations by using a fallback (e.g., `for _step in (_job[0].steps or []):`), or the type definition should strictly enforce `list[LocalBackendStep]` by removing `| None` from the Pydantic model definition.

### Environment

Kubernetes version:
```bash
N/A - This is a static code issue in the Python SDK.

```
Kubeflow Trainer version:
```bash
N/A

```
Kubeflow Python SDK version:
```bash
$ main (latest commit)

```

### Impacted by this bug?

Give it a 👍 We prioritize the issues with most 👍

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.