From 67ebe0b0cf687ad1ca397aafe9ca14159b72ce54 Mon Sep 17 00:00:00 2001 From: Igor Berman Date: Wed, 19 Jan 2022 21:45:45 +0200 Subject: [PATCH 1/4] Update base.py --- jupyterhub/apihandlers/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyterhub/apihandlers/base.py b/jupyterhub/apihandlers/base.py index 6cbb7659..896ac79f 100644 --- a/jupyterhub/apihandlers/base.py +++ b/jupyterhub/apihandlers/base.py @@ -201,7 +201,7 @@ class APIHandler(BaseHandler): 'pending': spawner.pending, 'ready': spawner.ready, 'url': url_path_join(spawner.user.url, spawner.name, '/'), - 'user_options': spawner.user_options, + 'user_options': spawner.orm_spawner.user_options, 'progress_url': spawner._progress_url, } scope_filter = self.get_scope_filter('admin:server_state') From 64d6f0222c791adbeb9e6ae18236cf68f4ba1154 Mon Sep 17 00:00:00 2001 From: Igor Berman Date: Thu, 20 Jan 2022 18:01:57 +0200 Subject: [PATCH 2/4] issue-3772: populating user_options from orm_spawner --- jupyterhub/apihandlers/base.py | 2 +- jupyterhub/user.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/jupyterhub/apihandlers/base.py b/jupyterhub/apihandlers/base.py index 896ac79f..6cbb7659 100644 --- a/jupyterhub/apihandlers/base.py +++ b/jupyterhub/apihandlers/base.py @@ -201,7 +201,7 @@ class APIHandler(BaseHandler): 'pending': spawner.pending, 'ready': spawner.ready, 'url': url_path_join(spawner.user.url, spawner.name, '/'), - 'user_options': spawner.orm_spawner.user_options, + 'user_options': spawner.user_options, 'progress_url': spawner._progress_url, } scope_filter = self.get_scope_filter('admin:server_state') diff --git a/jupyterhub/user.py b/jupyterhub/user.py index 039f4d11..8383df39 100644 --- a/jupyterhub/user.py +++ b/jupyterhub/user.py @@ -376,6 +376,7 @@ class User: oauth_client_id=client_id, cookie_options=self.settings.get('cookie_options', {}), trusted_alt_names=trusted_alt_names, + user_options=orm_spawner.user_options or {}, ) if self.settings.get('internal_ssl'): @@ -600,7 +601,7 @@ class User: spawner.handler = handler # Passing user_options to the spawner - if options is None: + if options is None or options is {}: # options unspecified, load from db which should have the previous value options = spawner.orm_spawner.user_options or {} else: From 9c8a4f287a20f572380f3c560528aacb50f2282b Mon Sep 17 00:00:00 2001 From: Igor Berman Date: Thu, 20 Jan 2022 18:04:35 +0200 Subject: [PATCH 3/4] issue-3772: populating user_options from orm_spawner, cleanup --- jupyterhub/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyterhub/user.py b/jupyterhub/user.py index 8383df39..f44bb10f 100644 --- a/jupyterhub/user.py +++ b/jupyterhub/user.py @@ -601,7 +601,7 @@ class User: spawner.handler = handler # Passing user_options to the spawner - if options is None or options is {}: + if options is None: # options unspecified, load from db which should have the previous value options = spawner.orm_spawner.user_options or {} else: From 2d6087959c4449fa1e4766c1a09063ac1b9057cb Mon Sep 17 00:00:00 2001 From: Igor Berman Date: Thu, 20 Jan 2022 20:07:43 +0200 Subject: [PATCH 4/4] issue-3772: populating user_options from orm_spawner; adding test --- jupyterhub/tests/test_spawner.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/jupyterhub/tests/test_spawner.py b/jupyterhub/tests/test_spawner.py index 2081abc0..1cbf398c 100644 --- a/jupyterhub/tests/test_spawner.py +++ b/jupyterhub/tests/test_spawner.py @@ -81,6 +81,18 @@ async def test_spawner(db, request): assert isinstance(status, int) +def test_spawner_from_db(app, user): + spawner = user.spawners['name'] + user_options = {"test": "value"} + spawner.orm_spawner.user_options = user_options + app.db.commit() + # delete and recreate the spawner from the db + user.spawners.pop('name') + new_spawner = user.spawners['name'] + assert new_spawner.orm_spawner.user_options == user_options + assert new_spawner.user_options == user_options + + async def wait_for_spawner(spawner, timeout=10): """Wait for an http server to show up