diff --git a/changelogs/fragments/47809-module_utils_mysql-unexpected-keyword-argument-cursorclass.yml b/changelogs/fragments/47809-module_utils_mysql-unexpected-keyword-argument-cursorclass.yml new file mode 100644 index 0000000000..2b13600e67 --- /dev/null +++ b/changelogs/fragments/47809-module_utils_mysql-unexpected-keyword-argument-cursorclass.yml @@ -0,0 +1,2 @@ +bugfixes: +- mysql - fixing unexpected keyword argument 'cursorclass' issue after migration from MySQLdb to PyMySQL. diff --git a/lib/ansible/module_utils/mysql.py b/lib/ansible/module_utils/mysql.py index 53c3cb1e4a..8237efc10d 100644 --- a/lib/ansible/module_utils/mysql.py +++ b/lib/ansible/module_utils/mysql.py @@ -31,9 +31,11 @@ import os try: import pymysql as mysql_driver + _mysql_cursor_param = 'cursor' except ImportError: try: import MySQLdb as mysql_driver + _mysql_cursor_param = 'cursorclass' except ImportError: mysql_driver = None @@ -75,6 +77,6 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='', db_connection = mysql_driver.connect(**config) if cursor_class is not None: - return db_connection.cursor(cursorclass=mysql_driver.cursors.DictCursor) + return db_connection.cursor(**{_mysql_cursor_param: mysql_driver.cursors.DictCursor}) else: return db_connection.cursor()