From 6751f2527460ba671bdc649c4b06a57fff8f12ab Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Tue, 26 Nov 2024 17:52:47 -0500 Subject: [PATCH] Check that environment exists when setting in config (#2578) * Check that environment exists when setting in config * Sort keys when exporting config to a dict --- modal/cli/config.py | 3 +++ modal/config.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modal/cli/config.py b/modal/cli/config.py index ccb83eeaa..50be747af 100644 --- a/modal/cli/config.py +++ b/modal/cli/config.py @@ -3,6 +3,7 @@ from rich.console import Console from modal.config import _profile, _store_user_config, config +from modal.environments import Environment config_cli = typer.Typer( name="config", @@ -38,6 +39,8 @@ def show(redact: bool = typer.Option(True, help="Redact the `token_secret` value @config_cli.command(help=SET_DEFAULT_ENV_HELP) def set_environment(environment_name: str): + # Confirm that the environment exists by looking it up + Environment.lookup(environment_name) _store_user_config({"environment": environment_name}) typer.echo(f"New default environment for profile {_profile}: {environment_name}") diff --git a/modal/config.py b/modal/config.py index 26e1b3a1e..6b359d76b 100644 --- a/modal/config.py +++ b/modal/config.py @@ -268,7 +268,7 @@ def __repr__(self): return repr(self.to_dict()) def to_dict(self): - return {key: self.get(key) for key in _SETTINGS.keys()} + return {key: self.get(key) for key in sorted(_SETTINGS)} config = Config()