From: Christian Heller Date: Fri, 14 Jun 2024 18:12:16 +0000 (+0200) Subject: Ensure stringy BaseModel IDs are not empty. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bprefix%7D%7D/static/blog?a=commitdiff_plain;h=99672306cdb97d76d00829b2e491f2df0abcbbd5;p=plomtask Ensure stringy BaseModel IDs are not empty. --- diff --git a/plomtask/db.py b/plomtask/db.py index 2077d79..b2f2142 100644 --- a/plomtask/db.py +++ b/plomtask/db.py @@ -245,6 +245,9 @@ class BaseModel(Generic[BaseModelId]): if isinstance(id_, int) and id_ < 1: msg = f'illegal {self.__class__.__name__} ID, must be >=1: {id_}' raise HandledException(msg) + if isinstance(id_, str) and "" == id_: + msg = f'illegal {self.__class__.__name__} ID, must be non-empty' + raise HandledException(msg) self.id_ = id_ def __eq__(self, other: object) -> bool: