module_utils/mysql: Fixing unexpected keyword argument 'cursorclass' error after migratio… (#47809)

* Fixing unexpected keyword argument 'cursorclass' error after migration from MySQLdb to PyMySQL

* Adoptions for mysql.py as suggested by felixfontein.

* Adding changelog fragment.

(cherry picked from commit 47190088b4)
This commit is contained in:
Timo Runge 2019-02-15 16:38:01 +01:00 committed by Toshio Kuratomi
parent b658139d63
commit 7e83675227
2 changed files with 5 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- mysql - fixing unexpected keyword argument 'cursorclass' issue after migration from MySQLdb to PyMySQL.

View file

@ -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()