Skip to content

Commit bfc1959

Browse files
zacdav-dbZac Davies
andauthored
Adjustments to config retrieval when schema is Databricks (mlflow#10117)
Signed-off-by: Zac Davies <[email protected]> Co-authored-by: Zac Davies <[email protected]>
1 parent 688e74b commit bfc1959

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

mlflow/R/mlflow/R/databricks-utils.R

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,48 @@ get_databricks_config_from_env <- function() {
7575
}
7676

7777
get_databricks_config <- function(profile) {
78-
config <- if (!is.na(profile)) {
79-
get_databricks_config_for_profile(profile)
80-
} else if (exists("spark.databricks.token") && exists("spark.databricks.api.url")) {
78+
79+
# If a profile is provided, fetch its configuration
80+
if (!is.na(profile)) {
81+
config <- get_databricks_config_for_profile(profile)
82+
if (databricks_config_is_valid(config)) {
83+
return(config)
84+
}
85+
}
86+
87+
# Check for environment variables
88+
config <- get_databricks_config_from_env()
89+
if (databricks_config_is_valid(config)) {
90+
return(config)
91+
}
92+
93+
# Check 'DEFAULT' profile
94+
config <- tryCatch({
95+
get_databricks_config_for_profile("DEFAULT")
96+
}, error = function(e) {
97+
# On error assume known invalid config
98+
list(host = NA, token = NA, username = NA, password = NA)
99+
})
100+
if (databricks_config_is_valid(config)) {
101+
return(config)
102+
}
103+
104+
# When in Databricks (done last so other methods are explicit overrides)
105+
if (exists("spark.databricks.token", envir = .GlobalEnv) &&
106+
exists("spark.databricks.api.url", envir = .GlobalEnv)) {
81107
config_vars <- list(
82108
host = get("spark.databricks.api.url", envir = .GlobalEnv),
83109
token = get("spark.databricks.token", envir = .GlobalEnv),
84110
insecure = Sys.getenv(config_variable_map$insecure, "False")
85111
)
86-
new_databricks_config(config_source = "db_dynamic", config_vars = config_vars)
87-
} else {
88-
config <- get_databricks_config_from_env()
112+
config <- new_databricks_config(config_source = "db_dynamic", config_vars = config_vars)
89113
if (databricks_config_is_valid(config)) {
90-
config
91-
} else {
92-
get_databricks_config_for_profile("DEFAULT")
114+
return(config)
93115
}
94116
}
95-
if (!databricks_config_is_valid(config)) {
96-
stop("Could not find valid Databricks configuration.")
97-
}
98-
config
117+
118+
# If no valid configuration is found by this point, raise an error
119+
stop("Could not find valid Databricks configuration.")
99120
}
100121

101122
#' Get information from Databricks Notebook environment

mlflow/R/mlflow/R/tracking-client.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ new_mlflow_client_impl <- function(get_host_creds, get_cli_env = list, class = c
2828
)
2929
}
3030

31-
new_mlflow_host_creds <- function( host = NA, username = NA, password = NA, token = NA,
31+
new_mlflow_host_creds <- function(host = NA, username = NA, password = NA, token = NA,
3232
insecure = "False") {
3333
insecure_arg <- if (is.null(insecure) || is.na(insecure)) {
3434
"False"

0 commit comments

Comments
 (0)