Fix kubernetes exception identity#3070
Conversation
Greptile SummaryThis PR fixes two distinct bugs: (1) a class identity mismatch where
Confidence Score: 5/5Safe to merge — both fixes are minimal, correct, and well-tested with no runtime-behavior regressions. All changes are straightforward bug fixes with accompanying regression tests. The Kubernetes exception identity fix is a one-line import swap with no behavioral side-effects. The card server fix correctly addresses both the Python 3.7+ StopIteration-in-generator prohibition and the off-by-one count. No P0 or P1 issues found. No files require special attention. Important Files Changed
Reviews (1): Last reviewed commit: "Unify KubernetesException across kuberne..." | Re-trigger Greptile |
PR Type
Summary
Fix Kubernetes unit-test failures caused by
KubernetesExceptionbeing defined in two different modules. The Kubernetes plugin now uses a single canonical exception class acrosskubernetes.pyandkube_utils.py.Issue
Fixes #2956
Reproduction
Runtime: local
Commands to run:
Where evidence shows up: test output in the local console
Before (error / log snippet)
while the tests expect:
This happens because kube_utils.py and kubernetes.py define separate KubernetesException classes, so pytest.raises(KubernetesException) in test_kubernetes.py does not match exceptions raised from kube_utils.py.
After (evidence that fix works)
The Kubernetes plugin defined KubernetesException in two places:
Helper functions such as validate_kube_labels and parse_kube_keyvalue_list raise the class from kube_utils.py, while the tests import KubernetesException from kubernetes.py.
Even though both classes have the same name and base class, they are distinct Python types. As a result, pytest.raises(KubernetesException) does not catch exceptions raised by the helper utilities, causing the Kubernetes unit tests to fail.
Why This Fix Is Correct
The fix restores the intended invariant that the Kubernetes plugin should expose one shared KubernetesException type across its modules.
It is intentionally minimal:
This avoids introducing a new exception module or reshaping the plugin layout for what is fundamentally a class identity bug.
Failure Modes Considered
Backward compatibility for existing imports
Code that imports KubernetesException from metaflow.plugins.kubernetes.kubernetes still works, because kubernetes.py continues to expose that name.
Runtime behavior changes in the Kubernetes backend
This change does not alter exception messages, error handling paths, or scheduling behavior. It only ensures that all Kubernetes-related code raises the same exception class.
Tests
Added a regression test in test/unit/test_kubernetes.py to verify that both modules reference the same KubernetesException class.
Locally validated the Kubernetes unit test file and confirmed all tests pass after the fix.
Non-Goals
This PR does not:
AI Tool Usage