mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-13 04:53:01 +00:00
remove handling of changing db sessions
this was purely for accessing the db from multiple threads in tests
This commit is contained in:
@@ -16,7 +16,6 @@ import shutil
|
|||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
import threading
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
if sys.version_info[:2] < (3, 3):
|
if sys.version_info[:2] < (3, 3):
|
||||||
@@ -423,7 +422,6 @@ class JupyterHub(Application):
|
|||||||
@observe('base_url')
|
@observe('base_url')
|
||||||
def _update_hub_prefix(self, change):
|
def _update_hub_prefix(self, change):
|
||||||
"""add base URL to hub prefix"""
|
"""add base URL to hub prefix"""
|
||||||
base_url = change['new']
|
|
||||||
self.hub_prefix = self._hub_prefix_default()
|
self.hub_prefix = self._hub_prefix_default()
|
||||||
|
|
||||||
cookie_secret = Bytes(
|
cookie_secret = Bytes(
|
||||||
@@ -813,15 +811,6 @@ class JupyterHub(Application):
|
|||||||
# store the loaded trait value
|
# store the loaded trait value
|
||||||
self.cookie_secret = secret
|
self.cookie_secret = secret
|
||||||
|
|
||||||
# thread-local storage of db objects
|
|
||||||
_local = Instance(threading.local, ())
|
|
||||||
|
|
||||||
@property
|
|
||||||
def db(self):
|
|
||||||
if not hasattr(self._local, 'db'):
|
|
||||||
self._local.db = scoped_session(self.session_factory)()
|
|
||||||
return self._local.db
|
|
||||||
|
|
||||||
def init_db(self):
|
def init_db(self):
|
||||||
"""Create the database connection"""
|
"""Create the database connection"""
|
||||||
self.log.debug("Connecting to db: %s", self.db_url)
|
self.log.debug("Connecting to db: %s", self.db_url)
|
||||||
@@ -833,7 +822,7 @@ class JupyterHub(Application):
|
|||||||
**self.db_kwargs
|
**self.db_kwargs
|
||||||
)
|
)
|
||||||
# trigger constructing thread local db property
|
# trigger constructing thread local db property
|
||||||
_ = self.db
|
self.db = scoped_session(self.session_factory)()
|
||||||
except OperationalError as e:
|
except OperationalError as e:
|
||||||
self.log.error("Failed to connect to db: %s", self.db_url)
|
self.log.error("Failed to connect to db: %s", self.db_url)
|
||||||
self.log.debug("Database error was:", exc_info=True)
|
self.log.debug("Database error was:", exc_info=True)
|
||||||
|
@@ -98,27 +98,7 @@ class User(HasTraits):
|
|||||||
if self.orm_user:
|
if self.orm_user:
|
||||||
return inspect(self.orm_user).session
|
return inspect(self.orm_user).session
|
||||||
|
|
||||||
@observe('db')
|
|
||||||
def _db_changed(self, change):
|
|
||||||
"""Changing db session reacquires ORM User object"""
|
|
||||||
# db session changed, re-get orm User
|
|
||||||
db = change.new
|
|
||||||
if self._user_id is not None:
|
|
||||||
# fetch our orm.User from the new db session
|
|
||||||
self.orm_user = db.query(orm.User).filter(orm.User.id == self._user_id).first()
|
|
||||||
# update our spawners' ORM objects with the new session,
|
|
||||||
# which can be found on our new orm_user.
|
|
||||||
for name, spawner in self.spawners.items():
|
|
||||||
spawner.orm_spawner = self.orm_user.orm_spawners[name]
|
|
||||||
|
|
||||||
_user_id = None
|
|
||||||
orm_user = Any(allow_none=True)
|
orm_user = Any(allow_none=True)
|
||||||
@observe('orm_user')
|
|
||||||
def _orm_user_changed(self, change):
|
|
||||||
if change.new:
|
|
||||||
self._user_id = change.new.id
|
|
||||||
else:
|
|
||||||
self._user_id = None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def authenticator(self):
|
def authenticator(self):
|
||||||
|
Reference in New Issue
Block a user