Skip to content

Commit

Permalink
Merge pull request #769 from GeorgianaElena/bug
Browse files Browse the repository at this point in the history
[bufix] Allow POST requests without profile_options specified (defaults will be used)
  • Loading branch information
consideRatio committed Aug 29, 2023
2 parents 5a90351 + 31fe6bb commit 934ef32
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
6 changes: 5 additions & 1 deletion kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3039,6 +3039,11 @@ def _validate_posted_profile_options(self, profile, selected_options):
one profile from being able to access options set for other
profiles
"""
# If the user didn't select anything, we don't have anything to validate
# as the implicit defaults will be used
if not selected_options:
return

for option_name, option in profile.get('profile_options').items():
unlisted_choice_form_key = f'{option_name}--unlisted-choice'
if option_name not in selected_options:
Expand Down Expand Up @@ -3167,7 +3172,6 @@ async def _load_profile(self, slug, profile_list, selected_profile_user_options)
chosen_option_overrides = option['choices'][chosen_option][
'kubespawner_override'
]

await self._apply_overrides(chosen_option_overrides)

# set of recognised user option keys
Expand Down
42 changes: 42 additions & 0 deletions tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,45 @@ async def test_find_slug_exception():
profile_list = spawner._populate_profile_list_defaults(profile_list)
with pytest.raises(ValueError):
spawner._get_profile('does-not-exist', profile_list)


async def test_empty_user_options_and_profile_options_api():
profiles = [
{
'display_name': 'CPU only',
'profile_options': {
'image': {
'display_name': 'Image',
'unlisted_choice': {
'enabled': True,
'display_name': 'Image Location',
'validation_regex': '^pangeo/.*$',
'validation_message': 'Must be a pangeo image, matching ^pangeo/.*$',
'kubespawner_override': {'image': '{value}'},
},
"choices": {
'op-1': {
'display_name': 'Option 1',
'kubespawner_override': {
'image': 'pangeo/pangeo-notebook:ebeb9dd'
},
},
'op-2': {
'display_name': 'Option 2',
'kubespawner_override': {
'image': 'pangeo/pangeo-notebook:latest'
},
},
},
}
},
},
]
spawner = KubeSpawner(_mock=True)
spawner.profile_list = profiles
# set user_options directly (e.g. via api)
spawner.user_options = {}

# nothing should be loaded yet
assert spawner.cpu_limit is None
await spawner.load_user_options()

0 comments on commit 934ef32

Please sign in to comment.