home · contact · privacy
Ensure stringy BaseModel IDs are not empty.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 14 Jun 2024 18:12:16 +0000 (20:12 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 14 Jun 2024 18:12:16 +0000 (20:12 +0200)
plomtask/db.py

index 2077d79f22450be197aa72fbbfccbc5a35a9b2e9..b2f2142c9c6957c19e90674270a1635082050f59 100644 (file)
@@ -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: