diff --git a/src/types/mlflow.jl b/src/types/mlflow.jl index 65f7c96..9d2e7aa 100644 --- a/src/types/mlflow.jl +++ b/src/types/mlflow.jl @@ -44,6 +44,11 @@ struct MLFlow apiroot = ENV["MLFLOW_TRACKING_URI"] end + # Automatically append /api to the tracking URI if missing to match standard MLflow REST paths. + if !endswith(apiroot, "/api") && !endswith(apiroot, "/api/") + apiroot = endswith(apiroot, "/") ? apiroot * "api" : apiroot * "/api" + end + if haskey(ENV, "MLFLOW_TRACKING_USERNAME") @warn "The provided username will be ignored as MLFLOW_TRACKING_USERNAME is set." username = ENV["MLFLOW_TRACKING_USERNAME"] diff --git a/test/types/mlflow.jl b/test/types/mlflow.jl index ff4fcbd..6c6bc13 100644 --- a/test/types/mlflow.jl +++ b/test/types/mlflow.jl @@ -6,7 +6,7 @@ instance = MLFlow("test", 2.0, Dict(), nothing, nothing) - @test instance.apiroot == "test" + @test instance.apiroot == "test/api" @test instance.apiversion == 2.0 @test instance.headers == Dict() @test isnothing(instance.username) @@ -20,7 +20,7 @@ instance = MLFlow("test") - @test instance.apiroot == "test" + @test instance.apiroot == "test/api" @test instance.apiversion == 2.0 @test instance.headers == Dict() @test isnothing(instance.username) @@ -71,4 +71,24 @@ @test_throws ErrorException MLFlow(; username="test", password="test", headers=Dict("Authorization" => "Basic $encoded_credentials")) end + + @testset "appending /api to tracking uri" begin + delete!(ENV, "MLFLOW_TRACKING_URI") + + instance_no_slash = MLFlow("https://dagshub.com/user/repo.mlflow") + @test instance_no_slash.apiroot == "https://dagshub.com/user/repo.mlflow/api" + + instance_with_slash = MLFlow("https://dagshub.com/user/repo.mlflow/") + @test instance_with_slash.apiroot == "https://dagshub.com/user/repo.mlflow/api" + + instance_already_api = MLFlow("https://dagshub.com/user/repo.mlflow/api") + @test instance_already_api.apiroot == "https://dagshub.com/user/repo.mlflow/api" + + instance_already_api_slash = MLFlow("https://dagshub.com/user/repo.mlflow/api/") + @test instance_already_api_slash.apiroot == "https://dagshub.com/user/repo.mlflow/api/" + + if !isnothing(mlflow_tracking_uri) + ENV["MLFLOW_TRACKING_URI"] = mlflow_tracking_uri + end + end end