Skip to content

Commit

Permalink
[DB] Fix labels setting in update_run (#1547)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedingber committed Dec 6, 2021
1 parent 9fea20b commit c187e5c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ endif
docker run \
--name=migration-db \
--rm \
-v $(pwd):/mlrun \
-v $(PWD):/mlrun \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD="pass" \
-e MYSQL_ROOT_HOST=% \
Expand Down Expand Up @@ -563,7 +563,7 @@ run-api: api ## Run mlrun api (dockerized)
run-test-db:
docker run \
--name=test-db \
-v $(pwd):/mlrun \
-v $(PWD):/mlrun \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD="" \
-e MYSQL_ALLOW_EMPTY_PASSWORD="true" \
Expand Down
5 changes: 1 addition & 4 deletions mlrun/api/db/sqldb/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ def update_run(self, session, updates: dict, uid, project="", iter=0):
start_time = run_start_time(struct)
if start_time:
run.start_time = start_time
run.labels.clear()
for name, value in run_labels(struct).items():
lbl = Run.Label(name=name, value=value, parent=run.id)
run.labels.append(lbl)
update_labels(run, run_labels(struct))
session.merge(run)
session.commit()
self._delete_empty_labels(session, Run.Label)
Expand Down
19 changes: 18 additions & 1 deletion tests/integration/sdk_api/run/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import tests.integration.sdk_api.base


class TestProject(tests.integration.sdk_api.base.TestMLRunIntegration):
class TestRun(tests.integration.sdk_api.base.TestMLRunIntegration):
def test_ctx_creation_creates_run_with_project(self):
ctx_name = "some-context"
mlrun.get_or_create_ctx(ctx_name)
Expand All @@ -11,3 +11,20 @@ def test_ctx_creation_creates_run_with_project(self):
)
assert len(runs) == 1
assert runs[0]["metadata"]["project"] == mlrun.mlconf.default_project

def test_ctx_state_change(self):
ctx_name = "some-context"
ctx = mlrun.get_or_create_ctx(ctx_name)
runs = mlrun.get_run_db().list_runs(
name=ctx_name, project=mlrun.mlconf.default_project
)
assert len(runs) == 1
assert runs[0]["status"]["state"] == mlrun.runtimes.constants.RunStates.running
ctx.set_state(mlrun.runtimes.constants.RunStates.completed)
runs = mlrun.get_run_db().list_runs(
name=ctx_name, project=mlrun.mlconf.default_project
)
assert len(runs) == 1
assert (
runs[0]["status"]["state"] == mlrun.runtimes.constants.RunStates.completed
)

0 comments on commit c187e5c

Please sign in to comment.