Skip to content

Commit 78d2649

Browse files
authored
Merge pull request #78 from aryawadhwa/fix-tracking-uri-api
Fix tracking URI to explicitly append /api to map to REST route
2 parents bc0e99a + 84e9fce commit 78d2649

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/types/mlflow.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ struct MLFlow
4444
apiroot = ENV["MLFLOW_TRACKING_URI"]
4545
end
4646

47+
# Automatically append /api to the tracking URI if missing to match standard MLflow REST paths.
48+
if !endswith(apiroot, "/api") && !endswith(apiroot, "/api/")
49+
apiroot = endswith(apiroot, "/") ? apiroot * "api" : apiroot * "/api"
50+
end
51+
4752
if haskey(ENV, "MLFLOW_TRACKING_USERNAME")
4853
@warn "The provided username will be ignored as MLFLOW_TRACKING_USERNAME is set."
4954
username = ENV["MLFLOW_TRACKING_USERNAME"]

test/types/mlflow.jl

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
instance = MLFlow("test", 2.0, Dict(), nothing, nothing)
88

9-
@test instance.apiroot == "test"
9+
@test instance.apiroot == "test/api"
1010
@test instance.apiversion == 2.0
1111
@test instance.headers == Dict()
1212
@test isnothing(instance.username)
@@ -20,7 +20,7 @@
2020

2121
instance = MLFlow("test")
2222

23-
@test instance.apiroot == "test"
23+
@test instance.apiroot == "test/api"
2424
@test instance.apiversion == 2.0
2525
@test instance.headers == Dict()
2626
@test isnothing(instance.username)
@@ -71,4 +71,24 @@
7171
@test_throws ErrorException MLFlow(; username="test", password="test",
7272
headers=Dict("Authorization" => "Basic $encoded_credentials"))
7373
end
74+
75+
@testset "appending /api to tracking uri" begin
76+
delete!(ENV, "MLFLOW_TRACKING_URI")
77+
78+
instance_no_slash = MLFlow("https://dagshub.com/user/repo.mlflow")
79+
@test instance_no_slash.apiroot == "https://dagshub.com/user/repo.mlflow/api"
80+
81+
instance_with_slash = MLFlow("https://dagshub.com/user/repo.mlflow/")
82+
@test instance_with_slash.apiroot == "https://dagshub.com/user/repo.mlflow/api"
83+
84+
instance_already_api = MLFlow("https://dagshub.com/user/repo.mlflow/api")
85+
@test instance_already_api.apiroot == "https://dagshub.com/user/repo.mlflow/api"
86+
87+
instance_already_api_slash = MLFlow("https://dagshub.com/user/repo.mlflow/api/")
88+
@test instance_already_api_slash.apiroot == "https://dagshub.com/user/repo.mlflow/api/"
89+
90+
if !isnothing(mlflow_tracking_uri)
91+
ENV["MLFLOW_TRACKING_URI"] = mlflow_tracking_uri
92+
end
93+
end
7494
end

0 commit comments

Comments
 (0)