MLflow exception error when trying to migrate models from Workspace Model Registry

Set the registry URI to the Workspace Model Registry before running the MLflow operations.

Written by jairo.prado

Last published at: January 16th, 2025

Problem

When you try to migrate models in your Workspace Model Registry to a Model Registry in Unity Catalog, you receive an error. 

 

root/.ipykernel/1712/command-5345605615358575-1459565655:51: FutureWarning: ``mlflow.tracking.client.MlflowClient.get_latest_versions`` is deprecated since 2.9.0. Model registry stages will be removed in a future major release. To learn more about the deprecation of model registry stages, see our migration guide here: https://mlflow.org/docs/latest/model-registry.html#migrating-from-stages
  model_versions = client.get_latest_versions(model_name)

MlflowException: Method 'get_latest_versions' is unsupported for models in the Unity Catalog. To load the latest version of a model in Unity Catalog, you can set an alias on the model version and load it by alias. See https://mlflow.org/docs/latest/model-registry.html#deploy-and-organize-models-with-aliases-and-tags for details.
File <command-345605615358575>, line 11
      8 model_name = "<model-name>"
     10 # Get the latest version (or specify a version)
---> 11 model_versions = client.get_latest_versions(model_name)
     13 # Print details of all versions
     14 for version_info in model_versions:

 

Cause

The default registry URI is set to Unity Catalog. The MLflow client is attempting to access the default URI instead of the Workspace Model Registry. 

 

Solution

Set the registry URI to the Workspace Model Registry before running the MLflow operations. Add the following line to your code to set the registry URI to your Workspace Model Registry.

 

```python
mlflow.set_registry_uri("databricks")
```