diff --git a/mlflow/models/model.py b/mlflow/models/model.py index 8d3446195cc4d..6ab542b2acddf 100644 --- a/mlflow/models/model.py +++ b/mlflow/models/model.py @@ -285,10 +285,8 @@ def __init__( **kwargs, ): # store model id instead of run_id and path to avoid confusion when model gets exported - if run_id: - self.run_id = run_id - self.artifact_path = artifact_path - + self.run_id = run_id + self.artifact_path = artifact_path self.utc_time_created = str(utc_time_created or datetime.utcnow()) self.flavors = flavors if flavors is not None else {} self.signature = signature diff --git a/tests/models/test_model.py b/tests/models/test_model.py index 13a82eacbf10f..6e4330532c1e5 100644 --- a/tests/models/test_model.py +++ b/tests/models/test_model.py @@ -479,3 +479,10 @@ def predict(self, context, model_input, params=None): assert loaded_model.saved_input_example_info["type"] == "json_object" loaded_example = loaded_model.load_input_example(local_path) assert loaded_example == input_example + + +def test_model_saved_by_save_model_can_be_loaded(tmp_path, sklearn_knn_model): + mlflow.sklearn.save_model(sklearn_knn_model, tmp_path) + info = Model.load(tmp_path).get_model_info() + assert info.run_id is None + assert info.artifact_path is None