Repository: apache/airflow

Issue:
Latest SQLAlchemy (1.4) Incompatible with latest sqlalchemy_utils
<!--

Welcome to Apache Airflow!  For a smooth issue process, try to answer the following questions.
Don't worry if they're not all applicable; just try to include what you can :-)

If you need to include code snippets or logs, please put them in fenced code
blocks.  If they're super-long, please use the details tag like
<details><summary>super-long log</summary> lots of stuff </details>

Please delete these comment blocks before submitting the issue.

-->

<!--

IMPORTANT!!!

PLEASE CHECK "SIMILAR TO X EXISTING ISSUES" OPTION IF VISIBLE
NEXT TO "SUBMIT NEW ISSUE" BUTTON!!!

PLEASE CHECK IF THIS ISSUE HAS BEEN REPORTED PREVIOUSLY USING SEARCH!!!

Please complete the next sections or the issue will be closed.
These questions are the first thing we need to know to understand the context.

-->

**Apache Airflow version**: 2.0.1


**Kubernetes version (if you are using kubernetes)** (use `kubectl version`): N/A

**Environment**:

- **Cloud provider or hardware configuration**:
- **OS** (e.g. from /etc/os-release): Mac OS Big Sur
- **Kernel** (e.g. `uname -a`):
- **Install tools**: pip 20.1.1
- **Others**:

**What happened**:

Our CI environment broke due to the release of SQLAlchemy 1.4, which is incompatible with the latest version of sqlalchemy-utils. ([Related issue](https://github.com/kvesteri/sqlalchemy-utils/issues/505))

Partial stacktrace:
```
  File "/Users/samwheating/Desktop/tmp_venv/lib/python3.7/site-packages/airflow/www/utils.py", line 27, in <module>
    from flask_appbuilder.models.sqla.interface import SQLAInterface
  File "/Users/samwheating/Desktop/tmp_venv/lib/python3.7/site-packages/flask_appbuilder/models/sqla/interface.py", line 16, in <module>
    from sqlalchemy_utils.types.uuid import UUIDType
  File "/Users/samwheating/Desktop/tmp_venv/lib/python3.7/site-packages/sqlalchemy_utils/__init__.py", line 1, in <module>
    from .aggregates import aggregated  # noqa
  File "/Users/samwheating/Desktop/tmp_venv/lib/python3.7/site-packages/sqlalchemy_utils/aggregates.py", line 372, in <module>
    from .functions.orm import get_column_key
  File "/Users/samwheating/Desktop/tmp_venv/lib/python3.7/site-packages/sqlalchemy_utils/functions/__init__.py", line 1, in <module>
    from .database import (  # noqa
  File "/Users/samwheating/Desktop/tmp_venv/lib/python3.7/site-packages/sqlalchemy_utils/functions/database.py", line 11, in <module>
    from .orm import quote
  File "/Users/samwheating/Desktop/tmp_venv/lib/python3.7/site-packages/sqlalchemy_utils/functions/orm.py", line 14, in <module>
    from sqlalchemy.orm.query import _ColumnEntity
ImportError: cannot import name '_ColumnEntity' from 'sqlalchemy.orm.query' (/Users/samwheating/Desktop/tmp_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py)
```

I'm not sure what the typical procedure is in the case of breaking changes to dependencies, but seeing as there's an upcoming release I thought it might be worth pinning sqlalchemy to 1.3.x? (Or pin the version of sqlalchemy-utils to a compatible version if one is released before Airflow 2.0.2)

**What you expected to happen**:

`airflow db init` to run successfully. 

<!-- What do you think went wrong? -->

**How to reproduce it**:

1) Create a new virtualenv
2) `pip install apache-airflow`
3) `airflow db init`

<!---

As minimally and precisely as possible. Keep in mind we do not have access to your cluster or dags.

If you are using kubernetes, please attempt to recreate the issue using minikube or kind.

## Install minikube/kind

- Minikube https://minikube.sigs.k8s.io/docs/start/
- Kind https://kind.sigs.k8s.io/docs/user/quick-start/

If this is a UI bug, please provide a screenshot of the bug or a link to a youtube video of the bug in action

You can include images using the .md style of
![alt text](http://url/to/img.png)

To record a screencast, mac users can use QuickTime and then create an unlisted youtube video with the resulting .mov file.

--->




Discussion:
Thanks for opening your first issue here! Be sure to follow the issue template!

Yeah. Might make sense. I will make a PR

Resolving patch:
diff --git a/airflow/upgrade/rules/fix_conf_not_importable_from_airflow.py b/airflow/upgrade/rules/fix_conf_not_importable_from_airflow.py
--- a/airflow/upgrade/rules/fix_conf_not_importable_from_airflow.py
+++ b/airflow/upgrade/rules/fix_conf_not_importable_from_airflow.py
@@ -22,8 +22,8 @@
 
 class ProperlyImportConfFromAirflow(BaseRule):
     """
-      ProperlyImportConfFromAirflow class to ensure proper import of conf to work in Airflow 2.0
-      """
+    ProperlyImportConfFromAirflow class to ensure proper import of conf to work in Airflow 2.0
+    """
     title = "Ensure Users Properly Import conf from Airflow"
     description = """\
     In Airflow-2.0, it's not possible to import `conf` from airflow by using `import conf from airflow`
diff --git a/airflow/upgrade/version.py b/airflow/upgrade/version.py
--- a/airflow/upgrade/version.py
+++ b/airflow/upgrade/version.py
@@ -15,4 +15,4 @@
 # specific language governing permissions and limitations
 # under the License.
 
-version = "1.3.0"
+version = "1.4.0"
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -481,8 +481,8 @@ def write_version(filename=os.path.join(*[my_dir, "airflow", "git_version"])):
 devel_all = (all_dbs + atlas + aws +
              devel_azure +
              celery + cgroups + crypto + datadog + devel + doc + docker +
-             elasticsearch + gcp + grpc + hashicorp + jdbc + jenkins + kerberos + kubernetes + ldap +
-             oracle + papermill + password +
+             elasticsearch + flask_oauth + gcp + grpc + hashicorp + jdbc + jenkins + kerberos + kubernetes +
+             ldap + oracle + papermill + password +
              rabbitmq + redis + samba + segment + sendgrid + sentry + slack + snowflake + ssh +
              virtualenv + webhdfs + zendesk)
 
@@ -645,7 +645,8 @@ def write_version(filename=os.path.join(*[my_dir, "airflow", "git_version"])):
     'requests>=2.20.0, <2.23.0;python_version<"3.0"',  # Required to keep snowflake happy
     'requests>=2.20.0, <2.24.0;python_version>="3.0"',  # Required to keep snowflake happy
     'setproctitle>=1.1.8, <2',
-    'sqlalchemy~=1.3',
+    # SQLAlchemy 1.4 breaks sqlalchemy-utils https://github.com/kvesteri/sqlalchemy-utils/issues/505
+    'sqlalchemy>=1.3.18, <1.4',
     'sqlalchemy_jsonfield==0.8.0;python_version<"3.5"',
     'sqlalchemy_jsonfield~=0.9;python_version>="3.5"',
     'tabulate>=0.7.5, <0.9',


Test patch: