Repository: spotify/luigi

Issue:
Enabling task history schedule
Hi, I'm new to Luigi.
Started working from the bottom with it about 2 months ago.
Now I have a few extracting and uploading tasks working just fine.

But now I'm feeling the need to check the history of the tasks and I can't seem to make it work.

Can someone help me with a step by step?
I can't find much info about that on the internet.

I tried doing what the docs says, using the parameters in the luigi.cfg.
But it looks like something is missing. Is there anything else I should do? Or its just it?

I keep getting the 500 error when accessing the /history and that's all.




Discussion:
@tgallasso what type of database are you using? 

FYI, I've had similar problems with the luigi dashboard's task history when connecting to MS SQL Server and recently found a fix for this. There are several relevant issues created a while back (#2769, #2370, #1921) for those using SQL Server, but I don't believe they were fixed.

Post your `luigi.cfg` and complete URL, may be we can help you, should you need anymore.
Just want to share that I'm currently having issues with MySQL + SQLAlchemy>=1.4.0.  I get the following error when navigating to /history:
```
Traceback (most recent call last):
  File "/home/luigi/.local/lib/python3.7/site-packages/tornado/web.py", line 1702, in _execute
    result = method(*self.path_args, **self.path_kwargs)
  File "/home/luigi/.local/lib/python3.7/site-packages/luigi/server.py", line 249, in get
    self.render("recent.html", tasks=tasks)
  File "/home/luigi/.local/lib/python3.7/site-packages/tornado/web.py", line 863, in render
    html = self.render_string(template_name, **kwargs)
  File "/home/luigi/.local/lib/python3.7/site-packages/tornado/web.py", line 1012, in render_string
    return t.generate(**namespace)
  File "/home/luigi/.local/lib/python3.7/site-packages/tornado/template.py", line 362, in generate
    return execute()
  File "recent_html.generated.py", line 44, in _tt_execute
    _tt_tmp = task.events[0].ts  # recent.html:19 (via layout.html:100)
  File "/home/luigi/.local/lib/python3.7/site-packages/sqlalchemy/orm/attributes.py", line 449, in __get__
    return self.impl.get(state, dict_)
  File "/home/luigi/.local/lib/python3.7/site-packages/sqlalchemy/orm/attributes.py", line 893, in get
    value = self.callable_(state, passive)
  File "/home/luigi/.local/lib/python3.7/site-packages/sqlalchemy/orm/strategies.py", line 830, in _load_for_state
    % (orm_util.state_str(state), self.key)
sqlalchemy.orm.exc.DetachedInstanceError: Parent instance <TaskRecord at 0x7f83372b4d50> is not bound to a Session; lazy load operation of attribute 'events' cannot proceed (Background on this error at: http://sqlalche.me/e/14/bhk3)
```
SQLAlchemy==1.3.23 seems to be fine though.

If others are still having issues or getting 500's, can you share the traceback from your logs?
@patrick7kelly Thanks for sharing, just got the same error with SQLite.

Resolving patch:
diff --git a/luigi/server.py b/luigi/server.py
--- 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):


Test patch: