From cefe506883e4b83d37417eff4ab00b7dc8ed3c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yolan=20Honor=C3=A9-Roug=C3=A9?= Date: Mon, 26 Aug 2024 21:25:04 +0200 Subject: [PATCH] :loud_sound: Improve error message for MlflowModelTrackingDataset.save when a run id is already active (#549) --- kedro_mlflow/io/models/mlflow_model_tracking_dataset.py | 8 +++----- tests/io/models/test_mlflow_model_tracking_dataset.py | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/kedro_mlflow/io/models/mlflow_model_tracking_dataset.py b/kedro_mlflow/io/models/mlflow_model_tracking_dataset.py index b91153a4..0250685d 100644 --- a/kedro_mlflow/io/models/mlflow_model_tracking_dataset.py +++ b/kedro_mlflow/io/models/mlflow_model_tracking_dataset.py @@ -102,11 +102,9 @@ def _save(self, model: Any) -> None: if mlflow.active_run(): # it is not possible to log in a run which is not the current opened one raise DatasetError( - "'run_id' cannot be specified" - " if there is an mlflow active run." - "Run_id mismatch: " - f"\n - 'run_id'={self._run_id}" - f"\n - active_run id={mlflow.active_run().info.run_id}" + f"'run_id' cannot be specified (run_id='{self._run_id}') " + f"if there is an mlflow active run (active run id='{mlflow.active_run().info.run_id}') " + f"See the rationale in this issue: https://github.com/Galileo-Galilei/kedro-mlflow/issues/549." ) else: # if the run id is specified and there is no opened run, diff --git a/tests/io/models/test_mlflow_model_tracking_dataset.py b/tests/io/models/test_mlflow_model_tracking_dataset.py index 4f5b188e..ff7bcb56 100644 --- a/tests/io/models/test_mlflow_model_tracking_dataset.py +++ b/tests/io/models/test_mlflow_model_tracking_dataset.py @@ -152,7 +152,7 @@ def test_save_sklearn_flavor_with_run_id_and_already_active_run(tracking_uri): with mlflow.start_run(): with pytest.raises( DatasetError, - match="'run_id' cannot be specified if there is an mlflow active run.", + match="if there is an mlflow active run", ): mlflow_model_ds.save(linreg_model)