From 6b028173a16d1f664dade0f70be661a3849f39a8 Mon Sep 17 00:00:00 2001
From: Jens Scheffler <jscheffl@apache.org>
Date: Sun, 13 Jul 2025 00:12:35 +0200
Subject: [PATCH 1/6] Cleanup type ignores in mysql provider where possible

---
 .../mysql/src/airflow/providers/mysql/hooks/mysql.py   | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py b/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
index ffee8ad187018..86812c5b27267 100644
--- a/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
+++ b/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
@@ -220,7 +220,7 @@ def get_conn(self) -> MySQLConnectionTypes:
                     "installed in case you see compilation error during installation."
                 )
 
-            conn_config = self._get_conn_config_mysql_client(conn)  # type: ignore[arg-type]
+            conn_config = self._get_conn_config_mysql_client(conn)
             return MySQLdb.connect(**conn_config)
 
         if client_name == "mysql-connector-python":
@@ -233,7 +233,7 @@ def get_conn(self) -> MySQLConnectionTypes:
                     "'mysql-connector-python'. Warning! It might cause dependency conflicts."
                 )
 
-            conn_config = self._get_conn_config_mysql_connector_python(conn)  # type: ignore[arg-type]
+            conn_config = self._get_conn_config_mysql_connector_python(conn)
             return mysql.connector.connect(**conn_config)
 
         raise ValueError("Unknown MySQL client name provided!")
@@ -253,7 +253,7 @@ def bulk_load(self, table: str, tmp_file: str) -> None:
             (tmp_file,),
         )
         conn.commit()
-        conn.close()  # type: ignore[misc]
+        conn.close()
 
     def bulk_dump(self, table: str, tmp_file: str) -> None:
         """Dump a database table into a tab-delimited file."""
@@ -270,7 +270,7 @@ def bulk_dump(self, table: str, tmp_file: str) -> None:
             (tmp_file,),
         )
         conn.commit()
-        conn.close()  # type: ignore[misc]
+        conn.close()
 
     @staticmethod
     def _serialize_cell(cell: object, conn: Connection | None = None) -> Any:
@@ -337,7 +337,7 @@ def bulk_load_custom(
 
         cursor.close()
         conn.commit()
-        conn.close()  # type: ignore[misc]
+        conn.close()
 
     def get_openlineage_database_info(self, connection):
         """Return MySQL specific information for OpenLineage."""

From ac630ea2604f8b9ae7e43c3a5c85ba4774170769 Mon Sep 17 00:00:00 2001
From: Jens Scheffler <jscheffl@apache.org>
Date: Sun, 13 Jul 2025 10:57:24 +0200
Subject: [PATCH 2/6] Revert two type ignore cleanups as long as imports with
 task sdk inconsistent

---
 providers/mysql/src/airflow/providers/mysql/hooks/mysql.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py b/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
index 86812c5b27267..ee1818329b097 100644
--- a/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
+++ b/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
@@ -220,7 +220,7 @@ def get_conn(self) -> MySQLConnectionTypes:
                     "installed in case you see compilation error during installation."
                 )
 
-            conn_config = self._get_conn_config_mysql_client(conn)
+            conn_config = self._get_conn_config_mysql_client(conn)  # type: ignore[arg-type]
             return MySQLdb.connect(**conn_config)
 
         if client_name == "mysql-connector-python":
@@ -233,7 +233,7 @@ def get_conn(self) -> MySQLConnectionTypes:
                     "'mysql-connector-python'. Warning! It might cause dependency conflicts."
                 )
 
-            conn_config = self._get_conn_config_mysql_connector_python(conn)
+            conn_config = self._get_conn_config_mysql_connector_python(conn)  # type: ignore[arg-type]
             return mysql.connector.connect(**conn_config)
 
         raise ValueError("Unknown MySQL client name provided!")

From 5d74debaa013210c6104ee9c7c7d08b1211247c3 Mon Sep 17 00:00:00 2001
From: Jens Scheffler <jscheffl@apache.org>
Date: Sun, 13 Jul 2025 11:40:53 +0200
Subject: [PATCH 3/6] Fix typing error and handling of undefined unicode

---
 .../mysql/src/airflow/providers/mysql/hooks/mysql.py     | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py b/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
index ee1818329b097..7d8e02c1c225c 100644
--- a/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
+++ b/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
@@ -30,7 +30,12 @@
 logger = logging.getLogger(__name__)
 
 if TYPE_CHECKING:
-    from airflow.models import Connection
+    from airflow.providers.mysql.version_compat import AIRFLOW_V_3_0_PLUS
+
+    if AIRFLOW_V_3_0_PLUS:
+        from airflow.models import Connection
+    else:
+        from airflow.models.connection import Connection
 
     try:
         from mysql.connector.abstracts import MySQLConnectionAbstract
@@ -130,7 +135,7 @@ def _get_conn_config_mysql_client(self, conn: Connection) -> dict:
 
         if conn.extra_dejson.get("charset", False):
             conn_config["charset"] = conn.extra_dejson["charset"]
-            if conn_config["charset"].lower() in ("utf8", "utf-8"):
+            if conn_config.get("charset", "undef").lower() in ("utf8", "utf-8"):
                 conn_config["use_unicode"] = True
         if conn.extra_dejson.get("cursor", False):
             try:

From ffe3c014e44e1c9d89b9a7dd5bc1b83b878f7c55 Mon Sep 17 00:00:00 2001
From: Jens Scheffler <95105677+jscheffl@users.noreply.github.com>
Date: Sun, 13 Jul 2025 11:46:59 +0200
Subject: [PATCH 4/6] Uuups

Co-authored-by: GPK <gopidesupavan@gmail.com>
---
 providers/mysql/src/airflow/providers/mysql/hooks/mysql.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py b/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
index 7d8e02c1c225c..f22854f15e111 100644
--- a/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
+++ b/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
@@ -33,7 +33,7 @@
     from airflow.providers.mysql.version_compat import AIRFLOW_V_3_0_PLUS
 
     if AIRFLOW_V_3_0_PLUS:
-        from airflow.models import Connection
+        from airflow.sdk import Connection
     else:
         from airflow.models.connection import Connection
 

From d000f668f0a718e76f5665adf492600ac3f9a199 Mon Sep 17 00:00:00 2001
From: Jens Scheffler <jscheffl@apache.org>
Date: Sun, 13 Jul 2025 12:13:35 +0200
Subject: [PATCH 5/6] Fix typing errors next round

---
 providers/mysql/src/airflow/providers/mysql/hooks/mysql.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py b/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
index f22854f15e111..a91c65dd1a13b 100644
--- a/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
+++ b/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
@@ -35,7 +35,7 @@
     if AIRFLOW_V_3_0_PLUS:
         from airflow.sdk import Connection
     else:
-        from airflow.models.connection import Connection
+        from airflow.models.connection import Connection  # type: ignore[assignment]
 
     try:
         from mysql.connector.abstracts import MySQLConnectionAbstract
@@ -135,7 +135,7 @@ def _get_conn_config_mysql_client(self, conn: Connection) -> dict:
 
         if conn.extra_dejson.get("charset", False):
             conn_config["charset"] = conn.extra_dejson["charset"]
-            if conn_config.get("charset", "undef").lower() in ("utf8", "utf-8"):
+            if str(conn_config.get("charset", "undef")).lower() in ("utf8", "utf-8"):
                 conn_config["use_unicode"] = True
         if conn.extra_dejson.get("cursor", False):
             try:

From cf7269683dfc443bd0c215d0866bf1774dff818d Mon Sep 17 00:00:00 2001
From: Jens Scheffler <jscheffl@apache.org>
Date: Sun, 13 Jul 2025 12:20:11 +0200
Subject: [PATCH 6/6] Fix typing errors next round, v2

---
 providers/mysql/src/airflow/providers/mysql/hooks/mysql.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py b/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
index a91c65dd1a13b..7fa2d6434194c 100644
--- a/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
+++ b/providers/mysql/src/airflow/providers/mysql/hooks/mysql.py
@@ -225,7 +225,7 @@ def get_conn(self) -> MySQLConnectionTypes:
                     "installed in case you see compilation error during installation."
                 )
 
-            conn_config = self._get_conn_config_mysql_client(conn)  # type: ignore[arg-type]
+            conn_config = self._get_conn_config_mysql_client(conn)
             return MySQLdb.connect(**conn_config)
 
         if client_name == "mysql-connector-python":
@@ -238,7 +238,7 @@ def get_conn(self) -> MySQLConnectionTypes:
                     "'mysql-connector-python'. Warning! It might cause dependency conflicts."
                 )
 
-            conn_config = self._get_conn_config_mysql_connector_python(conn)  # type: ignore[arg-type]
+            conn_config = self._get_conn_config_mysql_connector_python(conn)
             return mysql.connector.connect(**conn_config)
 
         raise ValueError("Unknown MySQL client name provided!")
