Fix shared cluster Py4j statefulness issue#19139
Conversation
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
|
Documentation preview for 3ca9258 is available at: More info
|
| try: | ||
| _capture_imported_modules("fake/model/path", "pyfunc") | ||
| except MlflowException: | ||
| pass |
There was a problem hiding this comment.
It's unclear whether this should succeed or fail. Let's use pytest.raises.
|
/review ✅ Review completed. Review OutputPerfect! I've completed the PR review. I found one issue that violates the Python style guide: Review SummaryPR: #19139 - Fix shared cluster Py4j statefulness issue Issues Found: 1 Issue Details
The implementation itself looks good - it correctly removes the PySpark gateway environment variables to prevent subprocess corruption of the parent process's py4j connection. The comments clearly explain why this is necessary. |
| "mlflow.utils.requirements_utils._download_artifact_from_uri", | ||
| return_value=str(tmp_path), | ||
| ), | ||
| ): |
There was a problem hiding this comment.
The mocked _run_command function should have an assertion to verify it was called. Without this, the test could pass even if _run_command is never invoked.
Consider adding an assertion after the try-except block:
| ): | |
| with ( | |
| mock.patch( | |
| "mlflow.utils.requirements_utils._run_command", | |
| side_effect=mock_run_command, | |
| ) as mock_run, | |
| mock.patch( | |
| "mlflow.utils.requirements_utils._download_artifact_from_uri", | |
| return_value=str(tmp_path), | |
| ), | |
| ): | |
| try: | |
| _capture_imported_modules("fake/model/path", "pyfunc") | |
| except MlflowException: | |
| pass | |
| mock_run.assert_called_once() | |
| assert "PYSPARK_GATEWAY_PORT" not in captured_env | |
| assert "PYSPARK_GATEWAY_SECRET" not in captured_env |
This follows the Python style guide rule: "Always Verify Mock Calls with Assertions" (see dev/guides/python.md).
🤖 Generated with Claude Code
There was a problem hiding this comment.
let's validate that the mock for _download_artifact_from_uri is used too.
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
🛠 DevTools 🛠
Install mlflow from this PR
For Databricks, use the following command:
Related Issues/PRs
#xxxWhat changes are proposed in this pull request?
Fix for shared clusters issue with py4j rejected connection timeouts when saving / logging models.
How is this PR tested?
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/tracking: Tracking Service, tracking client APIs, autologgingarea/models: MLmodel format, model serialization/deserialization, flavorsarea/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registryarea/scoring: MLflow Model server, model deployment tools, Spark UDFsarea/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflowsarea/gateway: MLflow AI Gateway client APIs, server, and third-party integrationsarea/prompts: MLflow prompt engineering features, prompt templates, and prompt managementarea/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionalityarea/projects: MLproject format, project running backendsarea/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/build: Build and test infrastructure for MLflowarea/docs: MLflow documentation pagesHow should the PR be classified in the release notes? Choose one:
rn/none- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/breaking-change- The PR will be mentioned in the "Breaking Changes" sectionrn/feature- A new user-facing feature worth mentioning in the release notesrn/bug-fix- A user-facing bug fix worth mentioning in the release notesrn/documentation- A user-facing documentation change worth mentioning in the release notesShould this PR be included in the next patch release?
Yesshould be selected for bug fixes, documentation updates, and other small changes.Noshould be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.What is a minor/patch release?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.