home · contact · privacy
Restore explicit ProcessStep node siblings replacing implicit ones.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 24 Dec 2024 08:09:01 +0000 (09:09 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 24 Dec 2024 08:09:01 +0000 (09:09 +0100)
plomtask/processes.py

index 3c8eebe2d4560825ec86bdaafa00ccf87131ddfe..ff459325e69cce8ae1869173d0381cf951984e59 100644 (file)
@@ -92,18 +92,22 @@ class Process(BaseModel[int], ConditionsRelations):
             owner_ids.add(id_)
         return [self.__class__.by_id(db_conn, id_) for id_ in owner_ids]
 
-    def get_steps(self, db_conn: DatabaseConnection, external_owner:
-                  Process | None = None) -> list[ProcessStepsNode]:
+    def get_steps(self,
+                  db_conn: DatabaseConnection,
+                  external_owner: Process | None = None
+                  ) -> list[ProcessStepsNode]:
         """Return tree of depended-on explicit and implicit ProcessSteps."""
 
         def make_node(step: ProcessStep, suppressed: bool) -> ProcessStepsNode:
-            is_explicit = False
-            if external_owner is not None:
-                is_explicit = step.owner_id == external_owner.id_
+            is_explicit = step.owner_id == top_owner.id_
             process = self.__class__.by_id(db_conn, step.step_process_id)
             step_steps = []
             if not suppressed:
-                step_steps = process.get_steps(db_conn, external_owner)
+                # exclude implicit siblings to explicit steps of same process
+                step_steps = [n for n in process.get_steps(db_conn, top_owner)
+                              if not [s for s in top_owner.explicit_steps
+                                      if s.parent_step_id == step.id_
+                                      and s.step_process_id == n.process.id_]]
             return ProcessStepsNode(step, process, is_explicit, step_steps,
                                     False, suppressed)
 
@@ -122,12 +126,11 @@ class Process(BaseModel[int], ConditionsRelations):
 
         step_nodes: list[ProcessStepsNode] = []
         seen_step_ids: Set[int] = set()
-        if external_owner is None:
-            external_owner = self
+        top_owner = external_owner or self
         for step in [s for s in self.explicit_steps
                      if s.parent_step_id is None]:
             assert isinstance(step.id_, int)
-            new_node = make_node(step, step in external_owner.suppressed_steps)
+            new_node = make_node(step, step in top_owner.suppressed_steps)
             step_nodes += [new_node]
         for step_node in step_nodes:
             walk_steps(step_node)