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.
pull/52341/head
Timo Runge 6 years ago committed by John R Barker
parent 958653e282
commit 47190088b4

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

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

Loading…
Cancel
Save