Skip to content

Commit

Permalink
Fix issue with mlflow.start_run(run_uuid=<deleted_run>) (mlflow#579)
Browse files Browse the repository at this point in the history
* init

* fix lint
  • Loading branch information
andrewmchen committed Oct 1, 2018
1 parent 188f534 commit c8cd4f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion mlflow/tracking/fluent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import sys
import time

from mlflow.entities import Experiment, Run, SourceType
from mlflow.entities import Experiment, Run, SourceType, RunInfo
from mlflow.exceptions import MlflowException
from mlflow.tracking.client import MlflowClient
from mlflow.utils import env
from mlflow.utils.databricks_utils import is_in_databricks_notebook, get_notebook_id, \
Expand Down Expand Up @@ -102,6 +103,9 @@ def start_run(run_uuid=None, experiment_id=None, source_name=None, source_versio
if existing_run_uuid:
_validate_run_id(existing_run_uuid)
active_run_obj = MlflowClient().get_run(existing_run_uuid)
if active_run_obj.info.lifecycle_stage == RunInfo.DELETED_LIFECYCLE:
raise MlflowException("Cannot start run with ID {} because it is in the "
"deleted state.".format(existing_run_uuid))
else:
if len(_active_run_stack) > 0:
parent_run_id = _active_run_stack[-1].info.run_uuid
Expand Down
18 changes: 15 additions & 3 deletions tests/tracking/test_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mlflow
from mlflow import tracking
from mlflow.entities import RunStatus
from mlflow.exceptions import MlflowException
from mlflow.tracking.fluent import start_run, end_run
from mlflow.utils.mlflow_tags import MLFLOW_PARENT_RUN_ID
from tests.projects.utils import tracking_uri_mock
Expand Down Expand Up @@ -193,14 +194,14 @@ def test_uri_types():


def test_with_startrun():
runId = None
run_id = None
import time
t0 = int(time.time() * 1000)
with mlflow.start_run() as active_run:
assert mlflow.active_run() == active_run
runId = active_run.info.run_uuid
run_id = active_run.info.run_uuid
t1 = int(time.time() * 1000)
run_info = mlflow.tracking._get_store().get_run(runId).info
run_info = mlflow.tracking._get_store().get_run(run_id).info
assert run_info.status == RunStatus.from_string("FINISHED")
assert t0 <= run_info.end_time and run_info.end_time <= t1
assert mlflow.active_run() is None
Expand All @@ -224,3 +225,14 @@ def verify_has_parent_id_tag(child_id, expected_parent_id):
mlflow.end_run()
mlflow.end_run()
assert mlflow.active_run() is None


def test_start_deleted_run():
run_id = None
with mlflow.start_run() as active_run:
run_id = active_run.info.run_uuid
tracking.MlflowClient().delete_run(run_id)
with pytest.raises(MlflowException, matches='because it is in the deleted state.'):
with mlflow.start_run(run_uuid=run_id):
pass
assert mlflow.active_run() is None

0 comments on commit c8cd4f4

Please sign in to comment.