about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2026-01-08 10:57:25 -0600
committerFrederick Muriuki Muriithi2026-01-08 10:57:25 -0600
commit0c1a27ec9d27cf2fefe47386ddf39d23a50f3628 (patch)
treec1fbd6ed1b46bdc2b13c9976214dc523ddb8afd8
parent5eaafdabf0e22b04907d6639600d2270211c4da5 (diff)
downloadgn-libs-0c1a27ec9d27cf2fefe47386ddf39d23a50f3628.tar.gz
Bug: Process the external ID before attempting to use it.
Process the external ID to ensure it is a valid value before
attempting to use it.
-rw-r--r--gn_libs/jobs/jobs.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/gn_libs/jobs/jobs.py b/gn_libs/jobs/jobs.py
index f5b7a5e..1ef6c0c 100644
--- a/gn_libs/jobs/jobs.py
+++ b/gn_libs/jobs/jobs.py
@@ -124,12 +124,21 @@ def initialise_job(# pylint: disable=[too-many-arguments, too-many-positional-ar
         job_type: str,
         extra_meta: Optional[dict] = None,
         expiry_seconds: int = _DEFAULT_EXPIRY_SECONDS_,
-        external_id: str = ""
+        external_id: Optional[Union[str, uuid.UUID]] = None
 ) -> dict:
     """Initialise the job and put the details in a SQLite3 database."""
     if extra_meta is None:
         extra_meta = {}
 
+    def __process_external_id__(_id: Optional[Union[str, uuid.UUID]]) -> str:
+        if isinstance(_id, uuid.UUID):
+            return str(_id)
+
+        if _id is not None and bool(_id.strip()):
+            return str(_id.strip())
+        return ""
+
+    _ext_id = __process_external_id__(external_id)
     _job = {
         "job_id": job_id,
         "command": shlex.join(command),
@@ -139,12 +148,10 @@ def initialise_job(# pylint: disable=[too-many-arguments, too-many-positional-ar
             "percent": 0,
             "job-type": job_type,
             **extra_meta,
-            **({"external_id": external_id.strip()}
-               if bool(external_id.strip())
-               else {})
+            **({"external_id": _ext_id} if bool(_ext_id) else {})
         }
     }
-    return __save_job__(conn, _job, expiry_seconds, external_id)
+    return __save_job__(conn, _job, expiry_seconds, _ext_id)
 
 
 def output_file(jobid: uuid.UUID, outdir: Path, stream: str) -> Path: