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:
parent
b658139d63
commit
7e83675227
2 changed files with 5 additions and 1 deletions
|
@ -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:
|
try:
|
||||||
import pymysql as mysql_driver
|
import pymysql as mysql_driver
|
||||||
|
_mysql_cursor_param = 'cursor'
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
import MySQLdb as mysql_driver
|
import MySQLdb as mysql_driver
|
||||||
|
_mysql_cursor_param = 'cursorclass'
|
||||||
except ImportError:
|
except ImportError:
|
||||||
mysql_driver = None
|
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)
|
db_connection = mysql_driver.connect(**config)
|
||||||
if cursor_class is not None:
|
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:
|
else:
|
||||||
return db_connection.cursor()
|
return db_connection.cursor()
|
||||||
|
|
Loading…
Reference in a new issue