Skip to content

Commit 82b74b8

Browse files
committed
SNOW-2306184: config refactor - connections toml merging split
1 parent fb5c8b5 commit 82b74b8

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

src/snowflake/cli/api/config_provider.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,17 @@ def _get_connection_dict_internal(self, connection_name: str) -> Dict[str, Any]:
448448
param_names.add(param_name)
449449

450450
# Get param names from flat keys (general env vars, SnowSQL env, CLI params)
451-
# Skip internal CLI arguments that aren't connection parameters
451+
# Skip internal CLI arguments and global settings that aren't connection parameters
452452
for key in self._config_cache.keys():
453-
if "." not in key and key not in ("enable_diag", "temporary_connection"):
453+
if "." not in key and key not in (
454+
"enable_diag",
455+
"temporary_connection",
456+
"default_connection_name",
457+
"connection_name",
458+
"diag_log_path",
459+
"diag_allowlist_path",
460+
"mfa_passcode",
461+
):
454462
param_names.add(key)
455463

456464
# For each parameter, determine the best value based on source priority

tests/test_config.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
from tests_common import IS_WINDOWS
3535

3636

37+
def is_config_ng_enabled():
38+
"""Check if config_ng is enabled via environment variable"""
39+
return os.getenv("SNOWFLAKE_CLI_CONFIG_V2_ENABLED") == "true"
40+
41+
3742
def test_empty_config_file_is_created_if_not_present():
3843
from snowflake.cli.api.utils.path_utils import path_resolver
3944

@@ -383,7 +388,12 @@ def assert_correct_connections_loaded():
383388
assert_correct_connections_loaded()
384389

385390

386-
def test_connections_toml_override_config_toml(
391+
# Legacy version - skip when config_ng is enabled
392+
@pytest.mark.skipif(
393+
is_config_ng_enabled(),
394+
reason="Legacy behavior: connections.toml replaces all connections from config.toml",
395+
)
396+
def test_connections_toml_override_config_toml_legacy(
387397
test_snowcli_config, snowflake_home, config_manager
388398
):
389399
connections_toml = snowflake_home / "connections.toml"
@@ -394,12 +404,49 @@ def test_connections_toml_override_config_toml(
394404
)
395405
config_init(test_snowcli_config)
396406

407+
# Legacy: Only connections from connections.toml are present
397408
assert get_default_connection_dict() == {"database": "overridden_database"}
398409
assert config_manager["connections"] == {
399410
"default": {"database": "overridden_database"}
400411
}
401412

402413

414+
# Config_ng version - skip when config_ng is NOT enabled
415+
@pytest.mark.skipif(
416+
not is_config_ng_enabled(),
417+
reason="Config_ng behavior: connections.toml merges with config.toml per-key",
418+
)
419+
def test_connections_toml_override_config_toml_config_ng(
420+
test_snowcli_config, snowflake_home, config_manager
421+
):
422+
"""Test config_ng behavior: connections.toml merges with config.toml per-key"""
423+
connections_toml = snowflake_home / "connections.toml"
424+
connections_toml.write_text(
425+
"""[default]
426+
database = "overridden_database"
427+
"""
428+
)
429+
config_init(test_snowcli_config)
430+
431+
# Config_ng: Merged - database from connections.toml, other keys from config.toml
432+
# The key difference from legacy: keys from config.toml are preserved
433+
default_conn = get_default_connection_dict()
434+
435+
# Key from connections.toml (level 3) overrides
436+
assert default_conn["database"] == "overridden_database"
437+
438+
# Keys from config.toml (level 2) are preserved
439+
assert default_conn["schema"] == "test_public"
440+
assert default_conn["role"] == "test_role"
441+
assert default_conn["warehouse"] == "xs"
442+
assert default_conn["password"] == "dummy_password"
443+
444+
# Verify other connections from config.toml are also accessible
445+
full_conn = get_connection_dict("full")
446+
assert full_conn["account"] == "dev_account"
447+
assert full_conn["user"] == "dev_user"
448+
449+
403450
parametrize_chmod = pytest.mark.parametrize(
404451
"chmod",
405452
[

0 commit comments

Comments
 (0)