home · contact · privacy
Ensure DB connections are closed even on erroneous/failing HTTP requests.
[plomtask] / plomtask / http.py
index 3710595d6c51378426c4575656d14c641dc125ef..f368232acd33dcc268ca296e69e0d34748f6fa2a 100644 (file)
@@ -110,10 +110,11 @@ class TaskHandler(BaseHTTPRequestHandler):
                 return
             else:
                 raise NotFoundException(f'Unknown page: /{site}')
-            conn.close()
             self._send_html(html)
         except HandledException as error:
             self._send_msg(error, code=error.http_code)
+        finally:
+            conn.close()
 
     def do_GET_calendar(self, conn: DatabaseConnection,
                         params: ParamsParser) -> str:
@@ -137,7 +138,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         id_ = params.get_int_or_none('id')
         process = Process.by_id(conn, id_, create=True)
         return self.server.jinja.get_template('process.html').render(
-                process=process, children=process.children(conn),
+                process=process, children=process.get_descendants(conn),
                 candidates=Process.all(conn))
 
     def do_GET_processes(self, conn: DatabaseConnection,
@@ -160,10 +161,11 @@ class TaskHandler(BaseHTTPRequestHandler):
             else:
                 msg = f'Page not known as POST target: /{site}'
                 raise NotFoundException(msg)
-            conn.close()
             self._redirect('/')
         except HandledException as error:
             self._send_msg(error, code=error.http_code)
+        finally:
+            conn.close()
 
     def do_POST_day(self, conn: DatabaseConnection, params: ParamsParser,
                     form_data: PostvarsParser) -> None: