Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the cursor type definition of mysql #43376

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions providers/src/airflow/providers/mysql/hooks/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,17 @@ def _get_conn_config_mysql_client(self, conn: Connection) -> dict:
if conn.extra_dejson.get("cursor", False):
import MySQLdb.cursors

if (conn.extra_dejson["cursor"]).lower() == "sscursor":
conn_config["cursorclass"] = MySQLdb.cursors.SSCursor
elif (conn.extra_dejson["cursor"]).lower() == "dictcursor":
conn_config["cursorclass"] = MySQLdb.cursors.DictCursor
elif (conn.extra_dejson["cursor"]).lower() == "ssdictcursor":
conn_config["cursorclass"] = MySQLdb.cursors.SSDictCursor
cursor_type = conn.extra_dejson.get("cursor", "").lower()
# Dictionary mapping cursor types to their respective classes
cursor_classes = {
"sscursor": MySQLdb.cursors.SSCursor,
"dictcursor": MySQLdb.cursors.DictCursor,
"ssdictcursor": MySQLdb.cursors.SSDictCursor,
}
# Set the cursor class in the connection configuration based on the cursor type
if cursor_type in cursor_classes:
conn_config["cursorclass"] = cursor_classes[cursor_type]

if conn.extra_dejson.get("ssl", False):
# SSL parameter for MySQL has to be a dictionary and in case
# of extra/dejson we can get string if extra is passed via
Expand Down