Repository: mlflow/mlflow

Issue:
[BUG] sqlite for backend store
### Willingness to contribute

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

### MLflow version

1.26

### System information

- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: 20.04
- **Python version**: 3.8
- **yarn version, if running the dev UI**:


### Describe the problem

Upgraded from 1.23, setting sqlite as backend store an sqlalchemy.future library error is produced.

A similar issue with this one
https://stackoverflow.com/questions/72341647/mlflow-modulenotfounderror-no-module-named-sqlalchemy-future/72432684#72432684

### Tracking information

mlflow server --backend-store-uri sqlite:///mlflow.sqlite  --default-artifact-root ./mlruns

### Code to reproduce issue

```
mlflow server --backend-store-uri sqlite:///mlflow.sqlite  --default-artifact-root ./mlruns
```

### Other info / logs

```
2022/05/30 13:18:36 ERROR mlflow.cli: Error initializing backend store
2022/05/30 13:18:36 ERROR mlflow.cli: No module named 'sqlalchemy.future'
Traceback (most recent call last):
lib/python3.8/site-packages/mlflow/store/tracking/sqlalchemy_store.py", line 11, in <module>
    from sqlalchemy.future import select
ModuleNotFoundError: No module named 'sqlalchemy.future'
```

### What component(s) does this bug affect?

- [X] `area/artifacts`: Artifact stores and artifact logging
- [ ] `area/build`: Build and test infrastructure for MLflow
- [X] `area/docs`: MLflow documentation pages
- [ ] `area/examples`: Example code
- [X] `area/model-registry`: Model Registry service, APIs, and the fluent client calls for Model Registry
- [ ] `area/models`: MLmodel format, model serialization/deserialization, flavors
- [ ] `area/projects`: MLproject format, project running backends
- [ ] `area/scoring`: MLflow Model server, model deployment tools, Spark UDFs
- [ ] `area/server-infra`: MLflow Tracking server backend
- [X] `area/tracking`: Tracking Service, tracking client APIs, autologging

### What interface(s) does this bug affect?

- [ ] `area/uiux`: Front-end, user experience, plotting, JavaScript, JavaScript dev server
- [ ] `area/docker`: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
- [X] `area/sqlalchemy`: Use of SQLAlchemy in the Tracking Service or Model Registry
- [ ] `area/windows`: Windows support

### What language(s) does this bug affect?

- [ ] `language/r`: R APIs and clients
- [ ] `language/java`: Java APIs and clients
- [ ] `language/new`: Proposals for new client languages

### What integration(s) does this bug affect?

- [ ] `integrations/azure`: Azure and Azure ML integrations
- [ ] `integrations/sagemaker`: SageMaker integrations
- [ ] `integrations/databricks`: Databricks integrations


Discussion:
@sniafas What version of `sqlalchemy` are you using?
I was able to reproduce the same issue with this command:

```
docker run --rm python:3.7 bash -c "pip install 'sqlalchemy<1.4' && python -c 'from sqlalchemy.future import select'"
```

The output is:

```
Collecting sqlalchemy<1.4
  Downloading SQLAlchemy-1.3.24-cp37-cp37m-manylinux2010_x86_64.whl (1.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.3/1.3 MB 10.8 MB/s eta 0:00:00
Installing collected packages: sqlalchemy
Successfully installed sqlalchemy-1.3.24
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 22.0.4; however, version 22.1.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'sqlalchemy.future'
```
Same 1.3.24. Do you think is a bug?

> @sniafas What version of `sqlalchemy` are you using?


@sniafas

> Do you think is a bug?

This looks like a regression to me. MLflow >= 1.24 uses `sqlalchemy.future.select` that sqlalchemy < 1.4 doesn't support.
https://github.com/mlflow/mlflow/pull/5382 added `from sqlalchemy.future import select`.
@sniafas One quick solution is to upgrade `sqlalchemy` to `>= 1.4.0`.
Replaced `sqlalchemy.future.select` with `sqlalchemy.sql.expression` in #5990, but didn't work in `sqlalchemy<1.4.0`.
There are two options to resolve this issue:

1. Pin `sqlalchemy`.
2. Find a workaround.
Tried with 1.4 and solved the issue! should I try a PR ?
The issue is [sqlalchemy 1.3.24](https://pypi.org/project/SQLAlchemy/1.3.24) is not that old (Released: Mar 31, 2021, roughly a year ago). We might need to keep mlflow compatible with it.
It'd be nice if we could find a workaround.
Hi @sniafas, we discussed this issue in the team and decided to drop support for `SQLAlchemy` 1.3. Would you be interested in filing a PR to update a `SQLAlchemy` requirement in `setup.py`?
Sure @harupy. Glad for asking! I ll give it a try, thanks!
@sniafas We can just make the following change:

```diff
diff --git a/setup.py b/setup.py
index adf20d1e6..8d73781b0 100644
--- a/setup.py
+++ b/setup.py
@@ -79,7 +79,7 @@ CORE_REQUIREMENTS = SKINNY_REQUIREMENTS + [
     # Pin sqlparse for: https://github.com/mlflow/mlflow/issues/3433
     "sqlparse>=0.3.1",
     # Required to run the MLflow server against SQL-backed storage
-    "sqlalchemy",
+    "sqlalchemy>=1.4.0",
     "waitress; platform_system == 'Windows'",
 ]
```

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -79,7 +79,7 @@ def package_files(directory):
     # Pin sqlparse for: https://github.com/mlflow/mlflow/issues/3433
     "sqlparse>=0.3.1",
     # Required to run the MLflow server against SQL-backed storage
-    "sqlalchemy",
+    "sqlalchemy>=1.4.0",
     "waitress; platform_system == 'Windows'",
 ]
 


Test patch: