cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Error Unable to Register Model to Unity Catalog

NicolaCompton
New Contributor II

I am following the examples outlined here:  https://learn.microsoft.com/en-us/azure/databricks/machine-learning/manage-model-lifecycle/ to register a model to unity catalog.

I keep getting this error : BlockingIOError: [Errno 11] Resource temporarily unavailable:

NicolaCompton_0-1748352021736.png

Any ideas how to resolve this?

Many thanks!

5 REPLIES 5

lingareddy_Alva
Honored Contributor II

Hi @NicolaCompton 

This is a common issue when running MLflow in Databricks environments.
The "Resource temporarily unavailable" error typically indicates a file system or process locking issue.
Here are several solutions to try:

Immediate Fixes
1. Set MLflow tracking URI explicitly:

import mlflow
import os

# Set the tracking URI to use Databricks workspace
mlflow.set_tracking_uri("databricks")

# Or try setting it to the workspace URL
# mlflow.set_tracking_uri("databricks://your-workspace-url")

2. Configure MLflow registry URI:

# For Unity Catalog
mlflow.set_registry_uri("databricks-uc")

# Then proceed with your model registration
model_uri = f"runs:/{run_id}/model"
mlflow.register_model(model_uri, "principal_analysts.nco.iris_model")

3. Add retry logic:

import time
import mlflow
from mlflow.exceptions import MlflowException

def register_model_with_retry(model_uri, model_name, max_retries=3):
for attempt in range(max_retries):
try:
return mlflow.register_model(model_uri, model_name)
except Exception as e:
if "Resource temporarily unavailable" in str(e) and attempt < max_retries - 1:
print(f"Attempt {attempt + 1} failed, retrying in 5 seconds...")
time.sleep(5)
else:
raise e

# Use it like this:
model_uri = f"runs:/{run_id}/model"
register_model_with_retry(model_uri, "principal_analysts.nco.iris_model")

 

 

 

LR

Thank you for your response.

Unfortunately, none of these solutions have worked for me. I think the issue is with getting the run_id. Do you have any ideas how to solve this?

Many thanks!

Hi @NicolaCompton 

Looking at your error, the issue is that run_id is not defined when you try to use it.
The problem is in how you're getting the run ID from the MLflow run object.
Here are the correct ways to fix this:

Solution 1: Fix the run_id extraction
The issue is in your code where you have:
autolog_run = mlflow.last_active_run()
model_uri = "runs:{}/model".format(autolog_run.info.run_id) # This line has the error

The correct way:

import mlflow
from sklearn import datasets
from sklearn.ensemble import RandomForestClassifier

# Set tracking URI
mlflow.set_tracking_uri("databricks")
mlflow.set_registry_uri("databricks-uc")

# Start MLflow run explicitly
with mlflow.start_run() as run:
# Train model
X, y = datasets.load_iris(return_X_y=True, as_frame=True)
clf = RandomForestClassifier(max_depth=7)
clf.fit(X, y)

# Log model
mlflow.sklearn.log_model(clf, "model")

# Get run_id from the active run
run_id = run.info.run_id

# Register model
model_uri = f"runs:/{run_id}/model"
mlflow.register_model(model_uri, "principal_analysts.nco.iris_model")

Solution 2: Use mlflow.active_run() instead

import mlflow
from sklearn import datasets
from sklearn.ensemble import RandomForestClassifier

mlflow.set_tracking_uri("databricks")
mlflow.set_registry_uri("databricks-uc")

with mlflow.start_run():
# Train model
X, y = datasets.load_iris(return_X_y=True, as_frame=True)
clf = RandomForestClassifier(max_depth=7)
clf.fit(X, y)

# Log model
mlflow.sklearn.log_model(clf, "model")

# Get current active run
current_run = mlflow.active_run()
run_id = current_run.info.run_id

# Register model
model_uri = f"runs:/{run_id}/model"
mlflow.register_model(model_uri, "principal_analysts.nco.iris_model")


The Key Fix
The main issue in your original code was this line:
run_id = run.info.run_id # 'run' was not defined in this scope


They properly capture the run_id within the correct scope where the run object is available.

The error you're seeing suggests that either:

The run variable is not in scope when you try to access run.info.run_id
The run object is None or doesn't have the expected structure

Try Solution 1 first - it's the most straightforward and should resolve your issue.

 

 

 

 

LR

NicolaCompton
New Contributor II

Thank you very much for your response and explanation.

Unfortunately, this takes me back to the original error. 

I have tried changing the set_tracking_uri to my workspace url and I get the same error.

Any ideas what this could be?

Hi @NicolaCompton 

This persistent "Resource temporarily unavailable" error in Databricks with
Unity Catalog is often related to workspace permissions or configuration issues.
Let's try several troubleshooting approaches:

Solution 1: Workspace URL Format
Make sure you're using the correct workspace URL format:

Solution 2: Check Unity Catalog Permissions

Solution 3: Minimal Test Setup
Try this minimal version to isolate the issue:

import mlflow
import mlflow.sklearn
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris

# Reset MLflow settings
mlflow.end_run() # End any existing runs

# Minimal configuration
mlflow.set_tracking_uri("databricks")

# Simple model training and registration
X, y = load_iris(return_X_y=True)
clf = RandomForestClassifier(n_estimators=10, max_depth=3)

with mlflow.start_run() as run:
clf.fit(X, y)
mlflow.sklearn.log_model(clf, "iris_model")
run_id = run.info.run_id
print(f"Run ID: {run_id}")

# Wait a moment for the run to finalize
import time
time.sleep(5)

# Try registration with error handling
try:
model_uri = f"runs:/{run_id}/iris_model"
result = mlflow.register_model(
model_uri=model_uri,
name="principal_analysts.nco.iris_simple_test"
)
print(f"Success! Model version: {result.version}")
except Exception as e:
print(f"Registration failed: {type(e).__name__}: {e}")

 

The "Resource temporarily unavailable" error often indicates either:
1. Insufficient permissions for Unity Catalog model registration
2. Workspace configuration issues
3. Temporary connectivity issues

Try Solution 3 first to isolate the problem, then work backwards to your full implementation.

 

 

LR