From 0c1a27ec9d27cf2fefe47386ddf39d23a50f3628 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 8 Jan 2026 10:57:25 -0600 Subject: 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. --- gn_libs/jobs/jobs.py | 17 ++++++++++++----- 1 file 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: -- cgit 1.4.1