From 5a696699dfc4d9526b90704a43983393ea5868a7 Mon Sep 17 00:00:00 2001 From: R James Cortese Date: Wed, 27 Apr 2022 21:11:08 -0400 Subject: [PATCH] Scope SQLA session so object lifespans rendering (#3153) Co-authored-by: Blair Azzopardi --- luigi/server.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/luigi/server.py b/luigi/server.py index 50948624d3..cc6d32a4f6 100644 --- a/luigi/server.py +++ b/luigi/server.py @@ -245,28 +245,32 @@ def from_utc(utcTime, fmt=None): class RecentRunHandler(BaseTaskHistoryHandler): def get(self): - tasks = self._scheduler.task_history.find_latest_runs() - self.render("recent.html", tasks=tasks) + with self._scheduler.task_history._session(None) as session: + tasks = self._scheduler.task_history.find_latest_runs(session) + self.render("recent.html", tasks=tasks) class ByNameHandler(BaseTaskHistoryHandler): def get(self, name): - tasks = self._scheduler.task_history.find_all_by_name(name) - self.render("recent.html", tasks=tasks) + with self._scheduler.task_history._session(None) as session: + tasks = self._scheduler.task_history.find_all_by_name(name, session) + self.render("recent.html", tasks=tasks) class ByIdHandler(BaseTaskHistoryHandler): def get(self, id): - task = self._scheduler.task_history.find_task_by_id(id) - self.render("show.html", task=task) + with self._scheduler.task_history._session(None) as session: + task = self._scheduler.task_history.find_task_by_id(id, session) + self.render("show.html", task=task) class ByParamsHandler(BaseTaskHistoryHandler): def get(self, name): payload = self.get_argument('data', default="{}") arguments = json.loads(payload) - tasks = self._scheduler.task_history.find_all_by_parameters(name, session=None, **arguments) - self.render("recent.html", tasks=tasks) + with self._scheduler.task_history._session(None) as session: + tasks = self._scheduler.task_history.find_all_by_parameters(name, session=session, **arguments) + self.render("recent.html", tasks=tasks) class RootPathHandler(BaseTaskHistoryHandler):