diff --git a/moonraker/components/history.py b/moonraker/components/history.py index 66a8ab49e..5276e4cc2 100644 --- a/moonraker/components/history.py +++ b/moonraker/components/history.py @@ -8,6 +8,7 @@ import time import logging from asyncio import Lock +from uuid import uuid4 from ..common import ( JobEvent, RequestType, @@ -122,7 +123,7 @@ class HistorySqlDefinition(SqlTableDefinition): prototype = ( f""" {HIST_TABLE} ( - job_id INTEGER PRIMARY KEY ASC, + job_id TEXT(36) PRIMARY KEY, user TEXT NOT NULL, filename TEXT, status TEXT NOT NULL, @@ -272,7 +273,7 @@ async def _handle_job_request(self, if req_type == RequestType.GET: job_id = web_request.get_str("uid") cursor = await self.history_table.execute( - f"SELECT * FROM {HIST_TABLE} WHERE job_id = ?", (int(job_id, 16),) + f"SELECT * FROM {HIST_TABLE} WHERE job_id = ?", (job_id), ) result = await cursor.fetchone() if result is None: @@ -298,7 +299,7 @@ async def _handle_job_request(self, job_id = web_request.get_str("uid") async with self.history_table as tx: cursor = await tx.execute( - f"DELETE FROM {HIST_TABLE} WHERE job_id = ?", (int(job_id, 16),) + f"DELETE FROM {HIST_TABLE} WHERE job_id = ?", (job_id,) ) if cursor.rowcount < 1: raise self.server.error(f"Invalid job uid: {job_id}", 404) @@ -421,7 +422,7 @@ async def add_job(self, job: PrinterJob) -> None: logging.info(f"Error saving job, filename '{job.filename}'") return self.current_job_id = new_id - job_id = f"{new_id:06X}" + job_id = str(uuid4()) self.update_metadata(job_id) logging.debug( f"History Job Added - Id: {job_id}, File: {job.filename}" diff --git a/moonraker/components/job_queue.py b/moonraker/components/job_queue.py index 41312f1ee..8c8ccb831 100644 --- a/moonraker/components/job_queue.py +++ b/moonraker/components/job_queue.py @@ -9,6 +9,7 @@ import time import logging from ..common import JobEvent, RequestType +from uuid import uuid4 # Annotation imports from typing import ( @@ -334,7 +335,7 @@ async def close(self): class QueuedJob: def __init__(self, filename: str, user: Optional[UserInfo] = None) -> None: self.filename = filename - self.job_id = f"{id(self):016X}" + self.job_id = str(uuid4()) self.time_added = time.time() self._user = user