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

replace mysql-python with pymysql for python3 compatibility #424

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions airflow/hooks/mysql_hook.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import MySQLdb
import MySQLdb.cursors
import pymysql
import pymysql.cursors

from airflow.hooks.dbapi_hook import DbApiHook


class MySqlHook(DbApiHook):
'''
Interact with MySQL.

You can specify charset in the extra field of your connection
as ``{"charset": "utf8"}``. Also you can choose cursor as
``{"cursor": "SSCursor"}``. Refer to the MySQLdb.cursors for more details.
``{"cursor": "SSCursor"}``. Refer to the pymysql.cursors for more details.
'''

conn_name_attr = 'mysql_conn_id'
Expand Down Expand Up @@ -41,11 +40,11 @@ def get_conn(self):
conn_config["use_unicode"] = True
if conn.extra_dejson.get('cursor', False):
if (conn.extra_dejson["cursor"]).lower() == 'sscursor':
conn_config["cursorclass"] = MySQLdb.cursors.SSCursor
conn_config["cursorclass"] = pymysql.cursors.SSCursor
elif (conn.extra_dejson["cursor"]).lower() == 'dictcursor':
conn_config["cursorclass"] = MySQLdb.cursors.DictCursor
conn_config["cursorclass"] = pymysql.cursors.DictCursor
elif (conn.extra_dejson["cursor"]).lower() == 'ssdictcursor':
conn_config["cursorclass"] = MySQLdb.cursors.SSDictCursor
conn_config["cursorclass"] = pymysql.cursors.SSDictCursor

conn = MySQLdb.connect(**conn_config)
conn = pymysql.connect(**conn_config)
return conn
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ ipython
jinja2
librabbitmq
markdown
mysql-python
nose
pandas
pygments
pyhive
pydruid
pymysql
PySmbClient
python-dateutil
#pyhs2
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'pyhive>=0.1.3',
'pyhs2>=0.6.0',
]
mysql = ['mysql-python>=1.2.5']
mysql = ['pymysql>=0.6.6']
postgres = ['psycopg2>=2.6']
optional = ['librabbitmq>=1.6.1']
samba = ['pysmbclient>=0.1.3']
Expand Down