X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=plomtask%2Fprocesses.py;h=0300e73ccbaec2f15a5478a892b9fcc9d231eaa3;hb=8aa3103f8e131b8925ac9daafadf2db77886c910;hp=8a5bf64d640ba4cd5d3d0aad7ea5306102d92670;hpb=8310bdb39e4f3cba5ac90be1ec57b3df633f436b;p=plomtask diff --git a/plomtask/processes.py b/plomtask/processes.py index 8a5bf64..0300e73 100644 --- a/plomtask/processes.py +++ b/plomtask/processes.py @@ -3,13 +3,16 @@ from __future__ import annotations from sqlite3 import Row from datetime import datetime from plomtask.db import DatabaseConnection +from plomtask.exceptions import NotFoundException, BadFormatException class Process: """Template for, and metadata for, Todos, and their arrangements.""" def __init__(self, id_: int | None) -> None: - self.id_ = id_ if id_ != 0 else None # to avoid DB-confusing rowid=0 + if (id_ is not None) and id_ < 1: + raise BadFormatException(f'illegal Process ID, must be >=1: {id_}') + self.id_ = id_ self.title = VersionedAttribute(self, 'title', 'UNNAMED') self.description = VersionedAttribute(self, 'description', '') self.effort = VersionedAttribute(self, 'effort', 1.0) @@ -35,15 +38,17 @@ class Process: return list(processes.values()) @classmethod - def by_id(cls, db_conn: DatabaseConnection, - id_: int | None, create: bool = False) -> Process | None: + def by_id(cls, db_conn: DatabaseConnection, id_: int | None, + create: bool = False) -> Process: """Collect all Processes and their connected VersionedAttributes.""" process = None for row in db_conn.exec('SELECT * FROM processes ' 'WHERE id = ?', (id_,)): process = cls(row[0]) break - if create and not process: + if not process: + if not create: + raise NotFoundException(f'Process not found of id: {id_}') process = Process(id_) if process: for row in db_conn.exec('SELECT * FROM process_titles '