QTZPOC-20

QTZPOC-20: Unify artifact code directory handling for all model flavors and standardize joblib pickle path

Implemented a robust mechanism to ensure an artifact's code/ directory is prepended to sys.path before loading for sklearn, pyfunc, and joblib flavors. sklearn and pyfunc now resolve MLflow URIs to local directories first to facilitate this sys.path modification. Standardized the joblib flavor to explicitly read and write model.pkl within the artifact directory. Updated documentation and added comprehensive tests to reflect these changes.
This commit is contained in:
2026-08-28 15:10:41 -03:00
parent f4c110cd8a
commit c1a44a9d7a
6 changed files with 475 additions and 273 deletions

View File

@@ -546,6 +546,15 @@ def patch_mlflow(mock_mlflow_models, joblib_flavor_artifacts):
mock_mlflow.pyfunc = MagicMock()
mock_mlflow.pyfunc.load_model = MagicMock(side_effect=mock_pyfunc_load_model)
# The sklearn and pyfunc paths resolve the URI to a local directory before loading, so that the
# artifact's `code/` can go on `sys.path` whatever the `MLmodel` manifest says. Echoing the URI
# keeps the loader stubs above — which branch on the URI text — working unchanged, and points
# the code-directory lookup at a path that does not exist.
mock_mlflow.artifacts = MagicMock()
mock_mlflow.artifacts.download_artifacts = MagicMock(
side_effect=lambda artifact_uri: str(artifact_uri)
)
# Mock other mlflow methods that might be called
mock_mlflow.set_tracking_uri = MagicMock()
mock_mlflow.get_run = MagicMock(