internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: mlflow/mlflow

Issue:
Move top-level name modules into its directory
We should keep each flavor module in a directory for consistency, an example PR is:  https://github.com/mlflow/mlflow/pull/9692 currently we just move everything into `__init__.py`, but in the future (bandwidth is the main concern) we shall refactor each module code into multiple files for clarify and readability.

We should do the same for the following:
- johnshowlabs.py
- keras.py
- lightgbm.py
- llm.py
- mleap.py
- onnx.py
- pmdarima.py
- prophet.py
- sentence_transformers.py
- shap.py
- spacy.py
- spark.py
- statsmodel.py

We will split the tasks into multiple small tasks so that new contributors can have a simple thing to work on. 


Discussion:
would like to take it :)
@AmirAflak Thanks! Actually let me put them into different issues so that more contributors can start trying out MLflow development.
<!-- assign-maintainer -->
@mlflow/mlflow-team Please assign a maintainer and start triaging this issue.
Is it possible to work on any of the remaining modules? It seems that, for example, the Prophet module has not been touched yet.
@montanarograziano Thanks, go ahead!
Since the issue does not exist yet, should I create one following the template of the others?
let's create one.
The remaining modules to address (no issues created yet) should be:

- onnx.py
- spark.py
- spacy.py
- statsmodels.py

If it's ok for you @harupy, I can work on these. 
thanks, let's work on these!
@montanarograziano I found a few more flavors we need to update.

- catboost
- h2o
- diviner

Would you be interested in updating them? No need to create new issues for them. One PR to update all of them is fine.
Sure, I'll work on these today.

Resolving patch:
diff --git a/mlflow/catboost.py b/mlflow/catboost/__init__.py
similarity index 100%
rename from mlflow/catboost.py
rename to mlflow/catboost/__init__.py
diff --git a/mlflow/diviner.py b/mlflow/diviner/__init__.py
similarity index 100%
rename from mlflow/diviner.py
rename to mlflow/diviner/__init__.py
diff --git a/mlflow/h2o.py b/mlflow/h2o/__init__.py
similarity index 100%
rename from mlflow/h2o.py
rename to mlflow/h2o/__init__.py


Test patch:
Repository: mlflow/mlflow

Issue:
[DOC-FIX] default value --env-manager for `mlflow models generate-dockerfile` is incorrect
### Willingness to contribute

Yes. I would be willing to contribute a document fix with guidance from the MLflow community.

### URL(s) with the issue

https://mlflow.org/docs/latest/cli.html#cmdoption-mlflow-models-generate-dockerfile-env-manager

### Description of proposal (what needs changing)

The documentation states that virtualenv is the default value, but actually it is conda, you can see it here:

https://github.com/mlflow/mlflow/blob/1404fa6db18269d3e32bc99acee44bfabb141f60/mlflow/models/cli.py#L197

Honestly, I would like to change the CLI and not the documentation to be consistent with the default value of `build-docker` which is virtualenv:

https://github.com/mlflow/mlflow/blob/1404fa6db18269d3e32bc99acee44bfabb141f60/mlflow/models/cli.py#L266

Should I change the docs or should I change the CLI source code?


Discussion:
@Beramos thanks for reporting this :) we should change the CLI source code.
@Beramos Please feel free to raise a PR and I'll review :) Thanks!

Resolving patch:
diff --git a/mlflow/models/cli.py b/mlflow/models/cli.py
--- a/mlflow/models/cli.py
+++ b/mlflow/models/cli.py
@@ -194,7 +194,7 @@ def generate_dockerfile(
         _logger.info("Generating Dockerfile for model %s", model_uri)
     else:
         _logger.info("Generating Dockerfile")
-    env_manager = env_manager or _EnvManager.CONDA
+    env_manager = env_manager or _EnvManager.VIRTUALENV
     backend = get_flavor_backend(model_uri, docker_build=True, env_manager=env_manager)
     if backend.can_build_image():
         backend.generate_dockerfile(


Test patch:
Repository: mlflow/mlflow

Issue:
Set `openai.api_key` if `OPENAI_API_KEY` exists
### Summary

The line that needs a fix:

https://github.com/mlflow/mlflow/blob/a4db4ee826765f0365944f83124af8840c72f4d8/mlflow/openai/utils.py#L161

Just because `"OPENAI_API_KEY" in os.environ` is True doesn't mean `openai.api_key` is set. The following code currently doens't work.

```python
import os

assert "OPENAI_API_KEY" not in os.environ

import openai

# Set OPENAI_API_KEY after openai is imported
os.environ["OPENAI_API_KEY"] = "..."

basic_qa_model = mlflow.openai.log_model(
    model="gpt-3.5-turbo",
    task=openai.ChatCompletion,
    artifact_path="model",
    messages=[
        {"role": "user", "content": "{question}"},
    ],
)
loaded_model = mlflow.pyfunc.load_model(basic_qa_model.model_uri)
loaded_model.predict(["What is MLflow"])  # this line throws because `openai.api_key` is None
```

### Notes

- Make sure to open a PR from a **non-master** branch.
- Sign off the commit using the `-s` flag when making a commit:

  ```sh
  git commit -s -m "..."
           # ^^ make sure to use this
  ```

- Include `#{issue_number}` (e.g. `#123`) in the PR description when opening a PR.



Discussion:

Resolving patch:
diff --git a/mlflow/openai/utils.py b/mlflow/openai/utils.py
--- a/mlflow/openai/utils.py
+++ b/mlflow/openai/utils.py
@@ -158,7 +158,13 @@ def __init__(self, api_type):
         self._api_token = None
         self._credential = None
         self._is_azure_ad = api_type in ("azure_ad", "azuread")
-        self._key_configured = bool(openai.api_key) or "OPENAI_API_KEY" in os.environ
+        self._key_configured = bool(openai.api_key)
+
+        # set the api key if it's not set. this is to deal with cases where the
+        # user sets the environment variable after importing the `openai` module
+        if not bool(openai.api_key) and "OPENAI_API_KEY" in os.environ:
+            openai.api_key = os.environ["OPENAI_API_KEY"]
+            self._key_configured = True
 
         if self._is_azure_ad and not self._key_configured:
             try:


Test patch:
diff --git a/tests/openai/test_openai_init.py b/tests/openai/test_openai_init.py
new file mode 100644
--- /dev/null
+++ b/tests/openai/test_openai_init.py
@@ -0,0 +1,26 @@
+import os
+from importlib import reload
+
+from mlflow.openai import _OAITokenHolder
+
+
+def test_set_api_key_on_tokenholder_init(monkeypatch):
+    # if the user sets the API key after the openai module,
+    # expect `openai.api_key` to not be set.
+    monkeypatch.delenv("OPENAI_API_KEY", False)
+    assert "OPENAI_API_KEY" not in os.environ
+
+    import openai
+
+    monkeypatch.setenv("OPENAI_API_KEY", "test-key")
+    assert openai.api_key is None
+
+    # when OAITokenHolder is initialized, expect it to set `openai.api_key`
+    token_holder = _OAITokenHolder("open_ai")
+    assert openai.api_key == "test-key"
+    assert token_holder._key_configured
+
+    # reload the module to simulate the env var being set before
+    # load. in this case we'd expect the API key to be present
+    reload(openai)
+    assert openai.api_key == "test-key"
Repository: mlflow/mlflow

Issue:
Support Flask 3.0 in MLflow
### Summary

We currently pin `Flask` to `< 3.0`. Flask 3.0 was recently released. We should update the requirement:

```diff
diff --git a/requirements/core-requirements.txt b/requirements/core-requirements.txt
index 99f4cdd62..11f7e3770 100644
--- a/requirements/core-requirements.txt
+++ b/requirements/core-requirements.txt
@@ -4,7 +4,7 @@
 
 alembic<2,!=1.10.0
 docker<7,>=4.0.0
-Flask<3
+Flask<4
 numpy<2
 scipy<2
 pandas<3
diff --git a/requirements/core-requirements.yaml b/requirements/core-requirements.yaml
index 5447b07c7..4ffb44c6b 100644
--- a/requirements/core-requirements.yaml
+++ b/requirements/core-requirements.yaml
@@ -17,7 +17,7 @@ docker:
 
 flask:
   pip_release: Flask
-  max_major_version: 2
+  max_major_version: 3
 
 numpy:
   pip_release: numpy
```

References:

- https://pypi.org/project/Flask/3.0.0/

### Notes

- Make sure to open a PR from a **non-master** branch.
- Sign off the commit using the `-s` flag when making a commit:

  ```sh
  git commit -s -m "..."
           # ^^ make sure to use this
  ```

- Include `#{issue_number}` (e.g. `#123`) in the PR description when opening a PR.



Discussion:
@Sai-Suraj-27 sorry, this issue already has an assignee.
@harupy Ok! but I saw that it was assigned yesterday and I see that assignee don't have a fork of mlflow as of now. So, I created a PR. Sorry for not asking before making a PR.
Please ask first if an issue has already an assignee.
> Please ask first if an issue has already an assignee.

Sure, from next time 😄. 

Resolving patch:
diff --git a/mlflow/server/__init__.py b/mlflow/server/__init__.py
--- a/mlflow/server/__init__.py
+++ b/mlflow/server/__init__.py
@@ -7,7 +7,6 @@
 import types
 
 from flask import Flask, Response, send_from_directory
-from flask import __version__ as flask_version
 from packaging.version import Version
 
 from mlflow.exceptions import MlflowException
@@ -40,7 +39,7 @@
 REL_STATIC_DIR = "js/build"
 
 app = Flask(__name__, static_folder=REL_STATIC_DIR)
-IS_FLASK_V1 = Version(flask_version) < Version("2.0")
+IS_FLASK_V1 = Version(importlib.metadata.version("flask")) < Version("2.0")
 
 
 for http_path, handler, methods in handlers.get_endpoints():


Test patch:
Repository: mlflow/mlflow

Issue:
Replace `pytest` with `dev/pytest.sh` in `mlflow/ml-package-versions.yml`
### Summary

A follow-up task for https://github.com/mlflow/mlflow/pull/10006. Replace `pytest` with `dev/pytest.sh` in `mlflow/ml-package-versions.yml` to enable the `fail-fast` behavior.


Example:

```diff
diff --git a/mlflow/ml-package-versions.yml b/mlflow/ml-package-versions.yml
index 4fdc2635d..373aa9e17 100644
--- a/mlflow/ml-package-versions.yml
+++ b/mlflow/ml-package-versions.yml
@@ -229,7 +229,7 @@ fastai:
       "< 2.8.0": ["torch<1.13.0", "torchvision<0.14.0"]
       ">= 2.8.0": ["torch", "torchvision"]
     run: |
-      pytest tests/fastai/test_fastai_autolog.py
+      dev/pytest.sh tests/fastai/test_fastai_autolog.py
 
 onnx:
   package_info:
```` 

### Notes

- Make sure to open a PR from a **non-master** branch.
- Sign off the commit using the `-s` flag when making a commit:

  ```sh
  git commit -s -m "..."
           # ^^ make sure to use this
  ```

- Include `Resolve #{issue_number}` (e.g. `Resolve #123`) in the PR description when opening a PR.



Discussion:
<!-- assign-maintainer -->
@mlflow/mlflow-team Please assign a maintainer and start triaging this issue.

Resolving patch:
diff --git a/conftest.py b/conftest.py
--- a/conftest.py
+++ b/conftest.py
@@ -100,6 +100,27 @@ def pytest_runtest_setup(item):
         pytest.skip("use `--requires-ssh` to run this test")
 
 
+def fetch_pr_labels():
+    """
+    Returns the labels associated with the current pull request.
+    """
+    if "GITHUB_ACTIONS" not in os.environ:
+        return None
+
+    if os.environ.get("GITHUB_EVENT_NAME") != "pull_request":
+        return None
+
+    with open(os.environ["GITHUB_EVENT_PATH"]) as f:
+        pr_data = json.load(f)
+        return [label["name"] for label in pr_data["pull_request"]["labels"]]
+
+
+def pytest_configure(config):
+    labels = fetch_pr_labels() or []
+    if "fail-fast" in labels:
+        config.option.maxfail = 1
+
+
 @pytest.hookimpl(hookwrapper=True)
 def pytest_report_teststatus(report, config):
     outcome = yield


Test patch:
Repository: mlflow/mlflow

Issue:
[BUG] Security Vulnerability



Discussion:

Resolving patch:
diff --git a/mlflow/utils/uri.py b/mlflow/utils/uri.py
--- a/mlflow/utils/uri.py
+++ b/mlflow/utils/uri.py
@@ -41,6 +41,10 @@ def is_local_uri(uri, is_tracking_or_registry_uri=True):
         return False
 
     parsed_uri = urllib.parse.urlparse(uri)
+    scheme = parsed_uri.scheme
+    if scheme == "":
+        return True
+
     if parsed_uri.hostname and not (
         parsed_uri.hostname == "."
         or parsed_uri.hostname.startswith("localhost")
@@ -48,8 +52,7 @@ def is_local_uri(uri, is_tracking_or_registry_uri=True):
     ):
         return False
 
-    scheme = parsed_uri.scheme
-    if scheme == "" or scheme == "file":
+    if scheme == "file":
         return True
 
     if is_windows() and len(scheme) == 1 and scheme.lower() == pathlib.Path(uri).drive.lower()[0]:


Test patch:
diff --git a/tests/utils/test_uri.py b/tests/utils/test_uri.py
--- a/tests/utils/test_uri.py
+++ b/tests/utils/test_uri.py
@@ -99,6 +99,8 @@ def test_is_local_uri():
     assert is_local_uri("file://localhost:5000/mlruns")
     assert is_local_uri("file://127.0.0.1/mlruns")
     assert is_local_uri("file://127.0.0.1:5000/mlruns")
+    assert is_local_uri("//proc/self/root")
+    assert is_local_uri("/proc/self/root")
 
     assert not is_local_uri("file://myhostname/path/to/file")
     assert not is_local_uri("https://whatever")
Repository: mlflow/mlflow

Issue:
Refactor for `subprocess.run`
### Summary

```diff
diff --git a/mlflow/models/wheeled_model.py b/mlflow/models/wheeled_model.py
index 0830208fe8..f64bf4194c 100644
--- a/mlflow/models/wheeled_model.py
+++ b/mlflow/models/wheeled_model.py
@@ -211,14 +211,23 @@ class WheeledModel:
             os.makedirs(dst_path)
 
         pip_wheel_options = MLFLOW_WHEELED_MODEL_PIP_DOWNLOAD_OPTIONS.get()
-
-        download_command = (
-            f"{sys.executable} -m pip wheel {pip_wheel_options} --wheel-dir={dst_path} -r"
-            f"{pip_requirements_path} --no-cache-dir"
-        )
-
         try:
-            subprocess.run([download_command], check=True, shell=True, capture_output=True)
+            subprocess.run(
+                [
+                    sys.executable,
+                    "-m",
+                    "pip",
+                    "wheel",
+                    pip_wheel_options,
+                    "--wheel-dir",
+                    dst_path,
+                    "-r",
+                    pip_requirements_path,
+                    "--no-cache-dir",
+                ],
+                check=True,
+                capture_output=True,
+            )
         except subprocess.CalledProcessError as e:
             raise MlflowException(
                 f"An error occurred while downloading the dependency wheels: {e.stderr}"
```

### Notes

- Make sure to open a PR from a **non-master** branch.
- Sign off the commit using the `-s` flag when making a commit:

  ```sh
  git commit -s -m "..."
           # ^^ make sure to use this
  ```

- Include `#{issue_number}` (e.g. `#123`) in the PR description when opening a PR.



Discussion:
Hello @harupy  sir, I accidently mixed two issues. can I close this pr and send new one. 
@Ankit8848 yes

Resolving patch:
diff --git a/mlflow/models/wheeled_model.py b/mlflow/models/wheeled_model.py
--- a/mlflow/models/wheeled_model.py
+++ b/mlflow/models/wheeled_model.py
@@ -212,13 +212,23 @@ def _download_wheels(cls, pip_requirements_path, dst_path):
 
         pip_wheel_options = MLFLOW_WHEELED_MODEL_PIP_DOWNLOAD_OPTIONS.get()
 
-        download_command = (
-            f"{sys.executable} -m pip wheel {pip_wheel_options} --wheel-dir={dst_path} -r"
-            f"{pip_requirements_path} --no-cache-dir"
-        )
-
         try:
-            subprocess.run([download_command], check=True, shell=True, capture_output=True)
+            subprocess.run(
+                [
+                    sys.executable,
+                    "-m",
+                    "pip",
+                    "wheel",
+                    pip_wheel_options,
+                    "--wheel-dir",
+                    dst_path,
+                    "-r",
+                    pip_requirements_path,
+                    "--no-cache-dir",
+                ],
+                check=True,
+                capture_output=True,
+            )
         except subprocess.CalledProcessError as e:
             raise MlflowException(
                 f"An error occurred while downloading the dependency wheels: {e.stderr}"


Test patch:
Repository: mlflow/mlflow

Issue:
[BUG] Security Vulnerability
Please check it here https://huntr.com/bounties/e3d7a994-bfd6-4772-ac9b-9aee1aa16a5f/


Discussion:

Resolving patch:
diff --git a/mlflow/store/artifact/local_artifact_repo.py b/mlflow/store/artifact/local_artifact_repo.py
--- a/mlflow/store/artifact/local_artifact_repo.py
+++ b/mlflow/store/artifact/local_artifact_repo.py
@@ -9,6 +9,7 @@
     mkdir,
     relative_path_to_artifact_path,
 )
+from mlflow.utils.uri import validate_path_is_safe
 
 
 class LocalArtifactRepository(ArtifactRepository):
@@ -74,8 +75,9 @@ def download_artifacts(self, artifact_path, dst_path=None):
         """
         if dst_path:
             return super().download_artifacts(artifact_path, dst_path)
-        # NOTE: The artifact_path is expected to be in posix format.
+        # NOTE: The artifact_path is expected to be a relative path in posix format.
         # Posix paths work fine on windows but just in case we normalize it here.
+        artifact_path = validate_path_is_safe(artifact_path)
         local_artifact_path = os.path.join(self.artifact_dir, os.path.normpath(artifact_path))
         if not os.path.exists(local_artifact_path):
             raise OSError(f"No such file or directory: '{local_artifact_path}'")
@@ -100,8 +102,9 @@ def list_artifacts(self, path=None):
             return []
 
     def _download_file(self, remote_file_path, local_path):
-        # NOTE: The remote_file_path is expected to be in posix format.
+        # NOTE: The remote_file_path is expected to be a relative path in posix format.
         # Posix paths work fine on windows but just in case we normalize it here.
+        remote_file_path = validate_path_is_safe(remote_file_path)
         remote_file_path = os.path.join(self.artifact_dir, os.path.normpath(remote_file_path))
         shutil.copy2(remote_file_path, local_path)
 


Test patch:
diff --git a/tests/store/artifact/test_local_artifact_repo.py b/tests/store/artifact/test_local_artifact_repo.py
--- a/tests/store/artifact/test_local_artifact_repo.py
+++ b/tests/store/artifact/test_local_artifact_repo.py
@@ -200,3 +200,8 @@ def test_delete_artifacts(local_artifact_repo):
 
 def test_delete_artifacts_with_nonexistent_path_succeeds(local_artifact_repo):
     local_artifact_repo.delete_artifacts("nonexistent")
+
+
+def test_download_artifacts_invalid_remote_file_path(local_artifact_repo):
+    with pytest.raises(MlflowException, match="Invalid path"):
+        local_artifact_repo.download_artifacts("/absolute/path/to/file")
diff --git a/tests/utils/test_promptlab_utils.py b/tests/utils/test_promptlab_utils.py
--- a/tests/utils/test_promptlab_utils.py
+++ b/tests/utils/test_promptlab_utils.py
@@ -104,4 +104,4 @@ def test_create_promptlab_run(store):
     # try to load the model
     import mlflow.pyfunc
 
-    mlflow.pyfunc.load_model(os.path.join(artifact_location, "model"))
+    mlflow.pyfunc.load_model(f"{artifact_location}/model")
Repository: mlflow/mlflow

Issue:
[DOC-FIX] Add JFrog MLFlow plugin in order to store your artifacts on a preferred JFrog repository
### Willingness to contribute

Yes. I can contribute a documentation fix independently.

### URL(s) with the issue

https://mlflow.org/docs/latest/plugins.html#artifact-repository-plugins

### Description of proposal (what needs changing)

Include details about the [mlflow-jfrog-plugin](https://pypi.org/project/mlflow-jfrog-plugin), and also provide simplified installation instructions, such as `pip install mlflow[jfrog]`


Discussion:

Resolving patch:
diff --git a/dev/pyproject.py b/dev/pyproject.py
--- a/dev/pyproject.py
+++ b/dev/pyproject.py
@@ -102,6 +102,7 @@ def build(skinny: bool) -> None:
                 "sqlserver": ["mlflow-dbstore"],
                 "aliyun-oss": ["aliyunstoreplugin"],
                 "xethub": ["mlflow-xethub"],
+                "jfrog": ["mlflow-jfrog-plugin"],
             },
             "urls": {
                 "homepage": "https://mlflow.org",


Test patch:
Repository: mlflow/mlflow

Issue:
[DOC-FIX] Document that attribute RunInfo.lifecycle_stage is of type LifecycleStage
### Willingness to contribute

No. I cannot contribute a documentation fix at this time.

### URL(s) with the issue

https://mlflow.org/docs/latest/python_api/mlflow.entities.html#mlflow.entities.RunInfo.lifecycle_stage

### Description of proposal (what needs changing)

For [documentation on RunInfo](https://mlflow.org/docs/latest/python_api/mlflow.entities.html#mlflow.entities.RunInfo) class.

For the `RunInfo.lifecycle_stage` attribute we should mention that it's type is  enum LifecycleStage. Analogous to the documentation for the `RunInfo.stage` attribute.

Should be
```
property lifecycle_stage[source]
  One of the values in mlflow.entities.lifecycle_stage.LifecycleStage describing the lifecycle stage of the run.
```
similar to the existing
```
property status[source]
  One of the values in mlflow.entities.RunStatus describing the status of the run.
```



Discussion:

Resolving patch:
diff --git a/mlflow/entities/run_info.py b/mlflow/entities/run_info.py
--- a/mlflow/entities/run_info.py
+++ b/mlflow/entities/run_info.py
@@ -138,6 +138,10 @@ def artifact_uri(self):
 
     @property
     def lifecycle_stage(self):
+        """
+        One of the values in :py:class:`mlflow.entities.lifecycle_stage.LifecycleStage`
+        describing the lifecycle stage of the run.
+        """
         return self._lifecycle_stage
 
     def to_proto(self):


Test patch:
Repository: mindsdb/mindsdb

Issue:
IndexError: list index out of range when missing predict value
**Is your feature request related to a problem? Please describe.**
When there is empty string provided as predict value e.g:
``` 
result = mdb.predict(predict=' ', model_name='home_rentals')
```
IndexError: list index out of range error is thrown

**Describe the solution you'd like**
User friendly message should be thrown e.g 
ValueError: Please provide valid predict value

**Additional context**
We can check for empty predict values in https://github.com/mindsdb/main/blob/76c691c4b18a4723626dfcbff8228da614d93e8b/mindsdb/libs/controllers/mindsdb_controller.py#L170 and raise Value error if predict not provided.


Discussion:
@torrmal I can make PR with fix. What is your opinion ?
Hi @ZoranPandovski thank you I apologize for the delay, I have been having some personal matters in the past week, anyway. It will be fantastic if you make a PR.

Resolving patch:
diff --git a/mindsdb/libs/controllers/mindsdb_controller.py b/mindsdb/libs/controllers/mindsdb_controller.py
--- a/mindsdb/libs/controllers/mindsdb_controller.py
+++ b/mindsdb/libs/controllers/mindsdb_controller.py
@@ -174,6 +174,9 @@ def predict(self, predict, from_data = None, when={}, model_name='mdsb_model', b
         :param model_name:
         :return:
         """
+        
+        if not predict:
+            raise ValueError('Please provide valid predict value.')
 
         transaction_type = TRANSACTION_PREDICT
 


Test patch: