From 94985b53302a452ec15ea23f2edd3e698889a34e Mon Sep 17 00:00:00 2001 From: Stephen Hartken Date: Thu, 21 May 2026 13:13:30 -0700 Subject: [PATCH] Fix KeyError crash in add_pending_resources on malformed squeue output Summary: Handle empty fields from `squeue` Reviewed By: calebho, luccabb Differential Revision: D105855425 --- gcm/monitoring/slurm/client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gcm/monitoring/slurm/client.py b/gcm/monitoring/slurm/client.py index 9387dc2..06d95e2 100644 --- a/gcm/monitoring/slurm/client.py +++ b/gcm/monitoring/slurm/client.py @@ -45,7 +45,10 @@ def add_pending_resources(message: dict[Any, Any]) -> None: """Adds an additional field ("PENDING_RESOURCES") to squeue output that tracks if the job is ready to be scheduled and waiting for resources.""" - if message["STATE"] == "PENDING" and message["REASON"] in PENDING_RESOURCE_REASONS: + if ( + message.get("STATE") == "PENDING" + and message.get("REASON") in PENDING_RESOURCE_REASONS + ): message["PENDING_RESOURCES"] = "True" else: message["PENDING_RESOURCES"] = "False"