diff --git a/libs/databrickscfg/ops.go b/libs/databrickscfg/ops.go index ab6fb3e111..e5c9c39063 100644 --- a/libs/databrickscfg/ops.go +++ b/libs/databrickscfg/ops.go @@ -38,9 +38,14 @@ func GetConfiguredDefaultProfile(ctx context.Context, configFilePath string) (st } // GetConfiguredDefaultProfileFrom returns the explicit default profile from -// [__settings__].default_profile, or "" when it is not set. +// [__settings__].default_profile, or "" when it is not set or when the value +// is the reserved __settings__ section name itself. func GetConfiguredDefaultProfileFrom(configFile *config.File) string { - return configFile.Section(databricksSettingsSection).Key(defaultProfileKey).String() + v := configFile.Section(databricksSettingsSection).Key(defaultProfileKey).String() + if v == databricksSettingsSection { + return "" + } + return v } // GetDefaultProfile returns the name of the default profile by loading the diff --git a/libs/databrickscfg/ops_test.go b/libs/databrickscfg/ops_test.go index bf4393a4f2..b418ec58a7 100644 --- a/libs/databrickscfg/ops_test.go +++ b/libs/databrickscfg/ops_test.go @@ -230,6 +230,11 @@ func TestGetDefaultProfile(t *testing.T) { content: "[no-host]\naccount_id = abc\n\n[profile1]\nhost = https://abc\n", want: "profile1", }, + { + name: "self-referencing __settings__ falls through to single profile", + content: "[__settings__]\ndefault_profile = __settings__\n\n[profile1]\nhost = https://abc\n", + want: "profile1", + }, } for _, tc := range testCases { @@ -280,6 +285,11 @@ func TestGetConfiguredDefaultProfile(t *testing.T) { content: "[__settings__]\n\n[profile1]\nhost = https://abc\n", want: "", }, + { + name: "self-referencing __settings__ is ignored", + content: "[__settings__]\ndefault_profile = __settings__\n\n[profile1]\nhost = https://abc\n", + want: "", + }, } for _, tc := range testCases {