From 99672306cdb97d76d00829b2e491f2df0abcbbd5 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Fri, 14 Jun 2024 20:12:16 +0200 Subject: [PATCH] Ensure stringy BaseModel IDs are not empty. --- plomtask/db.py | 3 +++ 1 file changed, 3 insertions(+) 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: -- 2.30.2