Skip to content

Commit

Permalink
Fix AttributeError in `DatabricksRestStore._paginate_list_experimen…
Browse files Browse the repository at this point in the history
…ts` (mlflow#4508)

* Fix page-token

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* page_token -> token

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
  • Loading branch information
harupy authored Jul 1, 2021
1 parent 4d4b462 commit 4c4c743
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mlflow/store/tracking/rest_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,6 @@ def _paginate_list_experiments(self, view_type):
experiments = self.list_experiments(view_type=view_type, page_token=page_token)
yield experiments

if not experiments.page_token:
if not experiments.token:
break
page_token = experiments.page_token
page_token = experiments.token
30 changes: 30 additions & 0 deletions tests/store/tracking/test_rest_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,36 @@ def rate_limit_response_fn(*args, **kwargs):
)
assert mock_http.call_count == 1

def test_databricks_paginate_list_experiments(self):
creds = MlflowHostCreds("https://hello")
store = DatabricksRestStore(lambda: creds)

list_exp_responses = []
next_page_tokens = ["a", "b", None]
for next_page_token in next_page_tokens:
experiment = Experiment(
experiment_id="123",
name=str(next_page_token),
artifact_location="/abc",
lifecycle_stage=LifecycleStage.ACTIVE,
)
list_exp_response = mock.MagicMock()
list_exp_response.text = json.dumps(
{
"experiments": [json.loads(message_to_json(experiment.to_proto()))],
"next_page_token": next_page_token,
}
)
list_exp_response.status_code = 200
list_exp_responses.append(list_exp_response)

with mock.patch("mlflow.utils.rest_utils.http_request", side_effect=list_exp_responses):
for idx, experiments in enumerate(
store._paginate_list_experiments(ViewType.ACTIVE_ONLY)
):
assert experiments[0].name == str(next_page_tokens[idx])
assert experiments.token == next_page_tokens[idx]


if __name__ == "__main__":
unittest.main()

0 comments on commit 4c4c743

Please sign in to comment.