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

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

Merged
merged 3 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- mysql - fixing unexpected keyword argument 'cursorclass' issue after migration from MySQLdb to PyMySQL.
4 changes: 3 additions & 1 deletion lib/ansible/module_utils/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@

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

Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand why mysql_driver.cursors.DictCursor is hardcoded here. mysql_replication passes 'mysql_driver.cursors.DictCursor' as cursor_class (and it is the only mysql_* module passing it), while most proxysql_* modules pass cursor_class=mysql_driver.cursors.DictCursor (and one or two doesn't pass it at all).

Either this should be named use_dict_cursor (or something like that), or it should be passed to db_connection.cursor() directly (and the call in mysql_replication should be changed). That's nothing you have to do for this PR, though, it's just a general rant after trying to understand what's going on :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I had the same problems trying to understand this; it's not really making sense but I just wanted to fix the problem which I've been facing with this cuserclass madness... :)

return db_connection.cursor(**{_mysql_cursor_param: mysql_driver.cursors.DictCursor})
else:
return db_connection.cursor()