You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "1fanwang (via GitHub)" <gi...@apache.org> on 2026/08/06 17:37:52 UTC

[PR] Fix MySQL metadata database failing when only PyMySQL is installed [airflow]

1fanwang opened a new pull request, #71251:
URL: https://github.com/apache/airflow/pull/71251

   `configure_adapters()` raises a `RuntimeError` telling the user to install
   `mysqlclient` whenever `mysqlclient` is absent — even when PyMySQL is installed
   and is the driver named in the connection string. The error is raised inside a
   `try` that only catches `ImportError`, so it escapes rather than falling through
   to the PyMySQL branch a few lines below, which the surrounding code clearly
   intends as the alternative:
   
   ```python
   try:
       try:
           import MySQLdb.converters
       except ImportError:
           raise RuntimeError("You do not have `mysqlclient` package installed. ...")
       MySQLdb.converters.conversions[Pendulum] = MySQLdb.converters.DateTime2literal
   except ImportError:          # cannot catch the RuntimeError above
       pass
   try:
       import pymysql.converters      # never reached when mysqlclient is missing
   ```
   
   The result is that `mysql+pymysql://` fails during `import airflow`, before any
   command runs. The docs recommend `mysqlclient` and note it is the only driver
   covered by CI, but they also point users at the SQLAlchemy MySQL dialect page if
   they want a different one, so hard-failing on this path is not intended.
   
   Each driver is now configured independently, and the error is raised only when
   neither is importable — which is the condition the message actually describes.
   
   related: #70235
   
   #70235 fixes a separate PyMySQL failure further along the same path — dynamic
   `PREPARE`/`EXECUTE` SQL inside migration `0017_2_9_2`. That one blocks a
   migration; this one blocks `import airflow` outright, so both are needed before
   `mysql+pymysql://` works end to end. The two changes do not overlap.
   
   ### Testing Done
   
   <details><summary>Raw logs</summary>
   
   **Before**, with PyMySQL installed and `mysqlclient` absent:
   
   ```
   $ airflow db migrate
   Traceback (most recent call last):
     File ".../airflow/settings.py", line 665, in configure_adapters
       import MySQLdb.converters
   ModuleNotFoundError: No module named 'MySQLdb'
   
   During handling of the above exception, another exception occurred:
     File ".../airflow/__init__.py", line 79, in <module>
       settings.initialize()
     File ".../airflow/settings.py", line 667, in configure_adapters
       raise RuntimeError(
   RuntimeError: You do not have `mysqlclient` package installed. Please install it
   with `pip install mysqlclient` ...
   ```
   
   **After**, same environment, `AIRFLOW__DATABASE__SQL_ALCHEMY_CONN=mysql+pymysql://...`:
   
   ```
   [info] Performing upgrade to the metadata database
   [info] Creating Airflow database tables from the ORM
   [info] Running stamp_revision  -> 7a98f1b7dbd3
   [info] Database migration done!
   ```
   
   followed by a real DAG run on that database:
   
   ```
   sum of squares = 55
   DagRun Finished: dag_id=tidb_smoke, run_duration=4.42, state=success
   ```
   
   **With neither driver installed** the error still fires, now naming both options.
   
   **Regressions**: `prek` static checks and `mypy-airflow-core` clean.
   
   </details>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix MySQL metadata database failing when only PyMySQL is installed [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #71251:
URL: https://github.com/apache/airflow/pull/71251


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org