Skip to content

Commit

Permalink
Check that environment exists when setting in config (#2578)
Browse files Browse the repository at this point in the history
* Check that environment exists when setting in config

* Sort keys when exporting config to a dict
  • Loading branch information
mwaskom authored Nov 26, 2024
1 parent 98bca3b commit 6751f25
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions modal/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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}")

Expand Down
2 changes: 1 addition & 1 deletion modal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 6751f25

Please sign in to comment.