This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 833efa47468 Fix MySQL metadata database failing when only PyMySQL is 
installed (#71251)
833efa47468 is described below

commit 833efa4746821825d1a1e87fa2ce6d9e9403c092
Author: Stefan Wang <[email protected]>
AuthorDate: Thu Aug 13 07:49:39 2026 -0700

    Fix MySQL metadata database failing when only PyMySQL is installed (#71251)
    
    configure_adapters() raised a RuntimeError telling the user to install
    mysqlclient whenever mysqlclient was absent, even though PyMySQL was
    present and is configured a few lines below. The RuntimeError was raised
    inside a try block that only catches ImportError, so it escaped instead of
    falling through to the PyMySQL branch as the surrounding code intended.
    
    Signed-off-by: 1fanwang <[email protected]>
    Co-authored-by: Jarek Potiuk <[email protected]>
---
 airflow-core/newsfragments/71251.bugfix.rst |  1 +
 airflow-core/src/airflow/settings.py        | 17 ++++++++---------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/airflow-core/newsfragments/71251.bugfix.rst 
b/airflow-core/newsfragments/71251.bugfix.rst
new file mode 100644
index 00000000000..ef127bdac38
--- /dev/null
+++ b/airflow-core/newsfragments/71251.bugfix.rst
@@ -0,0 +1 @@
+Fix ``import airflow`` failing with a ``RuntimeError`` demanding 
``mysqlclient`` when a MySQL connection string was configured and only 
``PyMySQL`` was installed. Each driver is now configured independently, and the 
error is raised only when neither is available.
diff --git a/airflow-core/src/airflow/settings.py 
b/airflow-core/src/airflow/settings.py
index 0a0e1c66197..ec2724abb5b 100644
--- a/airflow-core/src/airflow/settings.py
+++ b/airflow-core/src/airflow/settings.py
@@ -661,15 +661,7 @@ def configure_adapters():
 
     if SQL_ALCHEMY_CONN.startswith("mysql"):
         try:
-            try:
-                import MySQLdb.converters
-            except ImportError:
-                raise RuntimeError(
-                    "You do not have `mysqlclient` package installed. "
-                    "Please install it with `pip install mysqlclient` and make 
sure you have system "
-                    "mysql libraries installed, as well as well as 
`pkg-config` system package "
-                    "installed in case you see compilation error during 
installation."
-                )
+            import MySQLdb.converters
 
             MySQLdb.converters.conversions[Pendulum] = 
MySQLdb.converters.DateTime2literal
         except ImportError:
@@ -680,6 +672,13 @@ def configure_adapters():
             pymysql.converters.conversions[Pendulum] = 
pymysql.converters.escape_datetime
         except ImportError:
             pass
+        if "MySQLdb.converters" not in sys.modules and "pymysql.converters" 
not in sys.modules:
+            raise RuntimeError(
+                "You have a MySQL connection string but neither `mysqlclient` 
nor `PyMySQL` is "
+                "installed. Install one of them, e.g. `pip install 
mysqlclient` (make sure the "
+                "system mysql libraries and `pkg-config` are present in case 
you see a compilation "
+                "error during installation) or `pip install PyMySQL`."
+            )
 
 
 def _configure_secrets_masker():

Reply via email to