home · contact · privacy
Fix Process retrieval/display/saving bugs.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 22 Apr 2024 03:32:47 +0000 (05:32 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 22 Apr 2024 03:32:47 +0000 (05:32 +0200)
plomtask/http.py
plomtask/processes.py
templates/process.html
tests/processes.py

index 1009c1b6f7622bcfa92d1703c801db7ba8cd95f8..140f6bcfb16dbe89222b324d7e06bd7545f2f0f3 100644 (file)
@@ -161,7 +161,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         return {'process': process,
                 'steps': process.get_steps(self.conn),
                 'owners': process.used_as_step_by(self.conn),
-                'process_candidates': Process.all(self.conn),
+                'step_candidates': Process.all(self.conn),
                 'condition_candidates': Condition.all(self.conn)}
 
     def do_GET_processes(self) -> dict[str, object]:
index 32eee4d350db5ed78f4501f7016688f5c174c7cb..6249d48445a3488a8f8c4bdd5748b63a5a727ae5 100644 (file)
@@ -52,27 +52,29 @@ class Process(BaseModel, ConditionsRelations):
               create: bool = False) -> Process:
         """Collect Process, its VersionedAttributes, and its child IDs."""
         process = None
+        from_cache = False
         if id_:
-            process, _ = super()._by_id(db_conn, id_)
-        if not process:
-            if not create:
-                raise NotFoundException(f'Process not found of id: {id_}')
-            process = Process(id_)
-        if isinstance(process.id_, int):
-            for name in ('title', 'description', 'effort'):
-                table = f'process_{name}s'
-                for row in db_conn.row_where(table, 'parent', process.id_):
-                    getattr(process, name).history_from_row(row)
-            for row in db_conn.row_where('process_steps', 'owner',
-                                         process.id_):
-                step = ProcessStep.from_table_row(db_conn, row)
-                process.explicit_steps += [step]
-            for name in ('conditions', 'enables', 'disables'):
-                table = f'process_{name}'
-                for cond_id in db_conn.column_where(table, 'condition',
-                                                    'process', process.id_):
-                    target = getattr(process, name)
-                    target += [Condition.by_id(db_conn, cond_id)]
+            process, from_cache = super()._by_id(db_conn, id_)
+        if not from_cache:
+            if not process:
+                if not create:
+                    raise NotFoundException(f'Process not found of id: {id_}')
+                process = Process(id_)
+            if isinstance(process.id_, int):
+                for name in ('title', 'description', 'effort'):
+                    table = f'process_{name}s'
+                    for row in db_conn.row_where(table, 'parent', process.id_):
+                        getattr(process, name).history_from_row(row)
+                for row in db_conn.row_where('process_steps', 'owner',
+                                             process.id_):
+                    step = ProcessStep.from_table_row(db_conn, row)
+                    process.explicit_steps += [step]
+                for name in ('conditions', 'enables', 'disables'):
+                    table = f'process_{name}'
+                    for c_id in db_conn.column_where(table, 'condition',
+                                                     'process', process.id_):
+                        target = getattr(process, name)
+                        target += [Condition.by_id(db_conn, c_id)]
         assert isinstance(process, Process)
         return process
 
index 85424fa6750523487098d280b2568e48ad2f4c29..ec06d3a4c44232032266d07a1a1d42ab924632a4 100644 (file)
@@ -7,7 +7,6 @@
 {% if step_node.is_explicit %}
 <input type="checkbox" name="keep_step" value="{{step_id}}" checked />
 <input type="hidden" name="step_{{step_id}}_process_id" value="{{step_node.process.id_}}" />
-<input type="hidden" name="step_{{step_id}}_condition_id" value="{{step_node.condition.id_}}" />
 <input type="hidden" name="step_{{step_id}}_parent_id" value="{{step_node.parent_id or ''}}" />
 {% endif %}
 </td>
@@ -86,7 +85,7 @@ add enables: <input name="enables" list="condition_candidates" autocomplete="off
 add disables: <input name="disables" list="condition_candidates" autocomplete="off" />
 <h4>steps</h4>
 <table>
-{% for step_node in steps %}
+{% for step_id, step_node in steps.items() %}
 {{ step_with_steps(step_id, step_node, 0) }}
 {% endfor %}
 </table>
index 9413822291a87439aafda0cd39459c93b3905661..c718677f78e7afea5a95fdaa65e3c3981df96f1b 100644 (file)
@@ -135,12 +135,20 @@ class TestsWithDB(TestCaseWithDB):
         self.assertEqual(step.parent_step_id, step_retrieved.parent_step_id)
 
     def test_Process_singularity(self) -> None:
-        """Test pointers made for single object keep pointing to it."""
+        """Test pointers made for single object keep pointing to it, and
+        subsequent retrievals don't overload relations."""
         assert isinstance(self.proc1.id_, int)
         assert isinstance(self.proc2.id_, int)
+        c1 = Condition(None, False)
+        c1.save(self.db_conn)
+        assert isinstance(c1.id_, int)
+        self.proc1.set_conditions(self.db_conn, [c1.id_])
         self.proc1.set_steps(self.db_conn, [(None, self.proc2.id_, None)])
+        self.proc1.save(self.db_conn)
         p_retrieved = Process.by_id(self.db_conn, self.proc1.id_)
         self.assertEqual(self.proc1.explicit_steps, p_retrieved.explicit_steps)
+        self.assertEqual(self.proc1.conditions, p_retrieved.conditions)
+        self.proc1.save(self.db_conn)
 
     def test_Process_versioned_attributes_singularity(self) -> None:
         """Test behavior of VersionedAttributes on saving (with .title)."""