Browse Source

[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 năm trước cách đây
mục cha
commit
c31c1e8
1 tập tin đã thay đổi với 5 bổ sung3 xóa
  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