home · contact · privacy
Improve Condition tests and do minor fixes on the way.
[plomtask] / plomtask / conditions.py
index 539db9c0d50efb44e182137d7096c3d71a38345f..629510af868ae401c609b2c9307fa21f9c732c23 100644 (file)
@@ -19,6 +19,11 @@ class Condition(BaseModel[int]):
         self.description = VersionedAttribute(self, 'condition_descriptions',
                                               '')
 
+    def __lt__(self, other: Condition) -> bool:
+        assert isinstance(self.id_, int)
+        assert isinstance(other.id_, int)
+        return self.id_ < other.id_
+
     @classmethod
     def from_table_row(cls, db_conn: DatabaseConnection,
                        row: Row | list[Any]) -> Condition:
@@ -37,8 +42,13 @@ class Condition(BaseModel[int]):
         self.description.save(db_conn)
 
     def remove(self, db_conn: DatabaseConnection) -> None:
-        """Remove from DB, with dependencies."""
-        assert isinstance(self.id_, int)
+        """Remove from DB, with VersionedAttributes.
+
+        Checks for Todos and Processes that depend on Condition, prohibits
+        deletion if found.
+        """
+        if self.id_ is None:
+            raise HandledException('cannot remove unsaved item')
         for item in ('process', 'todo'):
             for attr in ('conditions', 'enables', 'disables'):
                 table_name = f'{item}_{attr}'