Deprecate Authenticator.db, Spawner.db

These objects should not access the shared db session;
add a warning pointing to Issue about their removal if it is accessed
This commit is contained in:
Min RK
2022-05-05 11:54:55 +02:00
parent 585b47051f
commit ac3ef1efc1
4 changed files with 40 additions and 3 deletions

View File

@@ -1129,7 +1129,7 @@ class JupyterHub(Application):
@default('authenticator') @default('authenticator')
def _authenticator_default(self): def _authenticator_default(self):
return self.authenticator_class(parent=self, db=self.db) return self.authenticator_class(parent=self, _deprecated_db_session=self.db)
implicit_spawn_seconds = Float( implicit_spawn_seconds = Float(
0, 0,

View File

@@ -10,6 +10,7 @@ from concurrent.futures import ThreadPoolExecutor
from functools import partial from functools import partial
from shutil import which from shutil import which
from subprocess import PIPE, STDOUT, Popen from subprocess import PIPE, STDOUT, Popen
from textwrap import dedent
try: try:
import pamela import pamela
@@ -31,6 +32,23 @@ class Authenticator(LoggingConfigurable):
db = Any() db = Any()
@default("db")
def _deprecated_db(self):
self.log.warning(
dedent(
"""
The shared database session at Authenticator.db is deprecated, and will be removed.
Please manage your own database and connections.
Contact JupyterHub at https://github.com/jupyterhub/jupyterhub/issues/3700
if you have questions or ideas about direct database needs for your Authenticator.
"""
),
)
return self._deprecated_db_session
_deprecated_db_session = Any()
enable_auth_state = Bool( enable_auth_state = Bool(
False, False,
config=True, config=True,

View File

@@ -14,6 +14,7 @@ import warnings
from inspect import signature from inspect import signature
from subprocess import Popen from subprocess import Popen
from tempfile import mkdtemp from tempfile import mkdtemp
from textwrap import dedent
from urllib.parse import urlparse from urllib.parse import urlparse
from async_generator import aclosing from async_generator import aclosing
@@ -157,9 +158,27 @@ class Spawner(LoggingConfigurable):
authenticator = Any() authenticator = Any()
hub = Any() hub = Any()
orm_spawner = Any() orm_spawner = Any()
db = Any()
cookie_options = Dict() cookie_options = Dict()
db = Any()
@default("db")
def _deprecated_db(self):
self.log.warning(
dedent(
"""
The shared database session at Spawner.db is deprecated, and will be removed.
Please manage your own database and connections.
Contact JupyterHub at https://github.com/jupyterhub/jupyterhub/issues/3700
if you have questions or ideas about direct database needs for your Spawner.
"""
),
)
return self._deprecated_db_session
_deprecated_db_session = Any()
@observe('orm_spawner') @observe('orm_spawner')
def _orm_spawner_changed(self, change): def _orm_spawner_changed(self, change):
if change.new and change.new.server: if change.new and change.new.server:

View File

@@ -411,7 +411,7 @@ class User:
authenticator=self.authenticator, authenticator=self.authenticator,
config=self.settings.get('config'), config=self.settings.get('config'),
proxy_spec=url_path_join(self.proxy_spec, server_name, '/'), proxy_spec=url_path_join(self.proxy_spec, server_name, '/'),
db=self.db, _deprecated_db_session=self.db,
oauth_client_id=client_id, oauth_client_id=client_id,
cookie_options=self.settings.get('cookie_options', {}), cookie_options=self.settings.get('cookie_options', {}),
trusted_alt_names=trusted_alt_names, trusted_alt_names=trusted_alt_names,