diff --git a/src/_nebari/stages/infrastructure/__init__.py b/src/_nebari/stages/infrastructure/__init__.py index a1b9f3773..9d34967e9 100644 --- a/src/_nebari/stages/infrastructure/__init__.py +++ b/src/_nebari/stages/infrastructure/__init__.py @@ -543,7 +543,7 @@ def check_provider(cls, values): # TODO: all cloud providers has required fields, but local and existing don't. # And there is no way to initialize a model without user input here. # We preserve the original behavior here, but we should find a better way to do this. - if provider in ["local", "existing"]: + if provider in ["local", "existing"] and provider not in values: values[provider] = provider_enum_model_map[provider]() else: # if the provider field is invalid, it won't be set when this validator is called diff --git a/tests/tests_unit/test_schema.py b/tests/tests_unit/test_schema.py index 21efe47c2..4f9dc23f9 100644 --- a/tests/tests_unit/test_schema.py +++ b/tests/tests_unit/test_schema.py @@ -137,3 +137,17 @@ def test_multiple_providers(config_schema): msg = r"Multiple providers set: \['local', 'existing'\]" with pytest.raises(ValidationError, match=msg): config_schema(**config_dict) + + +@pytest.mark.parametrize("provider", ["local", "existing"]) +def test_setted_provider(config_schema, provider): + config_dict = { + "project_name": "test", + "provider": provider, + f"{provider}": {"kube_context": "some_context"}, + } + config = config_schema(**config_dict) + assert config.provider == provider + result_config_dict = config.dict() + assert provider in result_config_dict + assert result_config_dict[provider]["kube_context"] == "some_context"