diff --git a/libs/cli/langgraph_cli/cli.py b/libs/cli/langgraph_cli/cli.py index b96e9f2a7..74df7aa3a 100644 --- a/libs/cli/langgraph_cli/cli.py +++ b/libs/cli/langgraph_cli/cli.py @@ -93,7 +93,8 @@ def _parse_env_from_config( ) -> dict[str, str]: """Resolve env vars from langgraph.json 'env' field or a .env fallback.""" env_field = config_json.get("env") - if isinstance(env_field, dict): + # validate_config_file will default env to {} + if isinstance(env_field, dict) and env_field: return {str(k): str(v) for k, v in env_field.items()} if isinstance(env_field, str): env_path = (config_path.parent / env_field).resolve() diff --git a/libs/cli/tests/unit_tests/test_deploy_helpers.py b/libs/cli/tests/unit_tests/test_deploy_helpers.py index 62b8c7194..e8287f6a3 100644 --- a/libs/cli/tests/unit_tests/test_deploy_helpers.py +++ b/libs/cli/tests/unit_tests/test_deploy_helpers.py @@ -104,6 +104,16 @@ class TestParseEnvFromConfig: result = _parse_env_from_config({}, config_path) assert result == {"DEFAULT_KEY": "default_val"} + def test_env_empty_dict_falls_back_to_dotenv(self, tmp_path, monkeypatch): + """validate_config defaults env to {}, should still fall back to .env.""" + env_file = tmp_path / ".env" + env_file.write_text("MY_KEY=my_val\n") + monkeypatch.chdir(tmp_path) + config_path = tmp_path / "langgraph.json" + config_path.touch() + result = _parse_env_from_config({"env": {}}, config_path) + assert result == {"MY_KEY": "my_val"} + def test_env_missing_no_dotenv_returns_empty(self, tmp_path, monkeypatch): monkeypatch.chdir(tmp_path) config_path = tmp_path / "langgraph.json"