diff --git a/src/prefect/infrastructure/kubernetes.py b/src/prefect/infrastructure/kubernetes.py index 2962dc214f97..c718fca5f30c 100644 --- a/src/prefect/infrastructure/kubernetes.py +++ b/src/prefect/infrastructure/kubernetes.py @@ -586,7 +586,7 @@ def _shortcut_customizations(self) -> JsonPatch: "prefect-job-" # We generate a name using a hash of the primary job settings + stable_hash( - *self.command, + *self.command if self.command else "", *self.env.keys(), *[v for v in self.env.values() if v is not None], ) diff --git a/tests/infrastructure/test_kubernetes_job.py b/tests/infrastructure/test_kubernetes_job.py index be6b68e5efbb..f679dc6fa15a 100644 --- a/tests/infrastructure/test_kubernetes_job.py +++ b/tests/infrastructure/test_kubernetes_job.py @@ -153,6 +153,14 @@ def test_building_a_job_is_idempotent(): assert first_time == second_time +def test_building_a_job_with_null_command(): + """ + Regression test for https://github.com/PrefectHQ/prefect/issues/14918 + """ + k8s_job = KubernetesJob(command=None) + k8s_job.build_job() + + def test_creates_job_by_building_a_manifest( mock_k8s_batch_client, mock_k8s_client,