Explorar o código

[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 %!s(int64=10) %!d(string=hai) anos
pai
achega
c31c1e8a5c
Modificáronse 1 ficheiros con 5 adicións e 3 borrados
  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