Skip to content

Commit b8c7e80

Browse files
author
Matthew Shipton
committed
Make dbx_client optional in import_run.py
1 parent e1e898a commit b8c7e80

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

mlflow_export_import/run/export_run.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from mlflow_export_import.common.timestamp_utils import fmt_ts_millis
1616
from mlflow_export_import.common.http_client import DatabricksHttpClient
1717
from mlflow_export_import.notebook.download_notebook import download_notebook
18+
from mlflow_export_import.common import MlflowExportImportException
19+
1820

1921
from mlflow.utils.mlflow_tags import MLFLOW_DATABRICKS_NOTEBOOK_PATH
2022
MLFLOW_DATABRICKS_NOTEBOOK_REVISION_ID = "mlflow.databricks.notebookRevisionID" # NOTE: not in mlflow/utils/mlflow_tags.py
@@ -32,8 +34,13 @@ def __init__(self, mlflow_client, notebook_formats=None):
3234
if notebook_formats is None:
3335
notebook_formats = []
3436
self.mlflow_client = mlflow_client
35-
self.dbx_client = DatabricksHttpClient()
36-
print("Databricks REST client:", self.dbx_client)
37+
try:
38+
self.dbx_client = DatabricksHttpClient()
39+
except MlflowExportImportException as e:
40+
print("WARNING: Databricks REST Client could not be initialized "
41+
"Notebook export functionality will be unavailable")
42+
else:
43+
print("Databricks REST client:", self.dbx_client)
3744
self.notebook_formats = notebook_formats
3845

3946

@@ -92,6 +99,8 @@ def export_run(self, run_id, output_dir):
9299

93100

94101
def _export_notebook(self, output_dir, notebook, run, fs):
102+
if self.dbx_client is None:
103+
raise MlflowExportImportException("Cannot export notebooks without an HTTP connection")
95104
notebook_dir = os.path.join(output_dir, "artifacts", "notebooks")
96105
fs.mkdirs(notebook_dir)
97106
revision_id = run.data.tags.get(MLFLOW_DATABRICKS_NOTEBOOK_REVISION_ID, None)

0 commit comments

Comments
 (0)