浏览代码

[notebook] Retry creating session if it failed at early stage before

In some case, the session type can not even be present in the list
of sessions.
Romain Rigaux 10 年之前
父节点
当前提交
c31c1e8a5c
共有 1 个文件被更改,包括 5 次插入3 次删除
  1. 5 3
      desktop/libs/notebook/src/notebook/connectors/base.py

+ 5 - 3
desktop/libs/notebook/src/notebook/connectors/base.py

@@ -32,14 +32,12 @@ LOG = logging.getLogger(__name__)
 class SessionExpired(Exception):
   pass
 
-
 class QueryExpired(Exception):
   pass
 
 class AuthenticationRequired(Exception):
   pass
 
-
 class QueryError(Exception):
   def __init__(self, message):
     self.message = message
@@ -115,7 +113,11 @@ def get_api(user, snippet, fs, jt):
 
 
 def _get_snippet_session(notebook, snippet):
-  return [session for session in notebook['sessions'] if session['type'] == snippet['type']][0]
+  session = [session for session in notebook['sessions'] if session['type'] == snippet['type']]
+  if not session:
+    raise SessionExpired()
+  else:
+    return session[0]
 
 
 # Base API