Repository: apache/airflow

Issue:
upgrade_check fails db version check
**Apache Airflow version**: 1.10.14 with AWS RDS mysql 5.7.26 as metastore db


**Kubernetes version (if you are using kubernetes)** (use `kubectl version`): v1.16.15

**Environment**: DEV

- **Cloud provider or hardware configuration**: AWS
- **OS** (e.g. from /etc/os-release): Debian GNU/Linux 10 (buster)
- **Kernel** (e.g. `uname -a`): Linux airflow-scheduler-765f664c56-4bsfq 4.14.186-146.268.amzn2.x86_64 #1 SMP Tue Jul 14 18:16:52 UTC 2020 x86_64 GNU/Linux
- **Install tools**: 
- **Others**: Running on K8S as docker container with apache/airflow:1.10.14 as base

**What happened**: Running `airflow upgrade_check` returns the following error:
```
airflow@airflow-web-54d6577c8b-g9vcn:/opt/airflow$ airflow upgrade_check

==================================================== STATUS ====================================================
Check for latest versions of apache-airflow and checker...............................................SUCCESS
Remove airflow.AirflowMacroPlugin class...............................................................SUCCESS
/home/airflow/.local/lib/python3.6/site-packages/airflow/utils/helpers.py:442: DeprecationWarning: Importing 'DummyOperator' directly from 'airflow.operators' has been deprecated. Please import from 'airflow.operators.[operator_module]' instead. Support for direct imports will be dropped entirely in Airflow 2.0.
  DeprecationWarning)
Ensure users are not using custom metaclasses in custom operators.....................................SUCCESS
Chain between DAG and operator not allowed............................................................SUCCESS
Connection.conn_type is not nullable..................................................................SUCCESS
Custom Executors now require full path................................................................SUCCESS
Traceback (most recent call last):
  File "/home/airflow/.local/bin/airflow", line 37, in <module>
    args.func(args)
  File "/home/airflow/.local/lib/python3.6/site-packages/airflow/upgrade/checker.py", line 118, in run
    all_problems = check_upgrade(formatter, rules)
  File "/home/airflow/.local/lib/python3.6/site-packages/airflow/upgrade/checker.py", line 38, in check_upgrade
    rule_status = RuleStatus.from_rule(rule)
  File "/home/airflow/.local/lib/python3.6/site-packages/airflow/upgrade/problem.py", line 44, in from_rule
    result = rule.check()
  File "/home/airflow/.local/lib/python3.6/site-packages/airflow/utils/db.py", line 74, in wrapper
    return func(*args, **kwargs)
  File "/home/airflow/.local/lib/python3.6/site-packages/airflow/upgrade/rules/postgres_mysql_sqlite_version_upgrade_check.py", line 56, in check
    installed_mysql_version = Version(session.execute('SELECT VERSION();').scalar())
  File "/home/airflow/.local/lib/python3.6/site-packages/packaging/version.py", line 298, in __init__
    raise InvalidVersion("Invalid version: '{0}'".format(version))
packaging.version.InvalidVersion: Invalid version: '5.7.26-log'
airflow@airflow-web-54d6577c8b-g9vcn:/opt/airflow$
```

**What you expected to happen**: commands runs through and prints helpful messages

<!-- What do you think went wrong? -->
Running `SELECT VERSION();').scalar()` against the metastore db returns "5.7.26-log' which is possibly not a valid value for Version class `__init__` function because of the "-log" ending?

```
mysql> select VERSION();
+------------+
| VERSION()  |
+------------+
| 5.7.26-log |
+------------+
1 row in set (0.00 sec)
```

**How to reproduce it**: Run `airflow upgrade_check` again.

**Anything else we need to know**: 
Dockerfile snippet:
```
FROM apache/airflow:1.10.14
...
USER ${AIRFLOW_UID}
RUN pip install --user \
    airflow-kubernetes-job-operator \
    apache-airflow-backport-providers-cncf-kubernetes \
    apache-airflow-backport-providers-ssh \
    apache-airflow-upgrade-check
```

How often does this problem occur? Once? Every time etc?: Every time since last week. Has worked before.



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


Resolving patch:
diff --git a/airflow/upgrade/rules/postgres_mysql_sqlite_version_upgrade_check.py b/airflow/upgrade/rules/postgres_mysql_sqlite_version_upgrade_check.py
--- a/airflow/upgrade/rules/postgres_mysql_sqlite_version_upgrade_check.py
+++ b/airflow/upgrade/rules/postgres_mysql_sqlite_version_upgrade_check.py
@@ -43,16 +43,23 @@ def check(self, session=None):
             min_req_sqlite_version = Version('3.15')
             installed_sqlite_version = Version(session.execute('select sqlite_version();').scalar())
             if installed_sqlite_version < min_req_sqlite_version:
-                return "From Airflow 2.0, SQLite version below 3.15 is no longer supported. \n" + more_info
+                return "From Airflow 2.0, SQLite version below {} is no longer supported. \n{}".format(
+                    min_req_sqlite_version, more_info
+                )
 
         elif "postgres" in conn_str:
             min_req_postgres_version = Version('9.6')
             installed_postgres_version = Version(session.execute('SHOW server_version;').scalar())
             if installed_postgres_version < min_req_postgres_version:
-                return "From Airflow 2.0, PostgreSQL version below 9.6 is no longer supported. \n" + more_info
+                return "From Airflow 2.0, PostgreSQL version below {} is no longer supported. \n{}".format(
+                    min_req_postgres_version, more_info
+                )
 
         elif "mysql" in conn_str:
             min_req_mysql_version = Version('5.7')
-            installed_mysql_version = Version(session.execute('SELECT VERSION();').scalar())
+            # special treatment is needed here, because MySQL version may include a suffix like '-log'
+            installed_mysql_version = Version(session.execute('SELECT VERSION();').scalar().split('-')[0])
             if installed_mysql_version < min_req_mysql_version:
-                return "From Airflow 2.0, MySQL version below 5.7 is no longer supported. \n" + more_info
+                return "From Airflow 2.0, MySQL version below {} is no longer supported. \n{}".format(
+                    min_req_mysql_version, more_info
+                )


Test patch: