Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/types/mlflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
24 changes: 22 additions & 2 deletions test/types/mlflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Loading