Skip to content

Commit

Permalink
Merge pull request #640 from SimpleHQ/allow_auto_commit_in_mysql_oper…
Browse files Browse the repository at this point in the history
…ator

[MySqlOperator] Fix issue apache/airflow#459 - mysql error 2014

GitOrigin-RevId: 3646c9b30d48105a15280965d5a3338ceccfef98
  • Loading branch information
mistercrunch authored and Cloud Composer Team committed Sep 16, 2024
1 parent 83f6544 commit 8d14662
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions airflow/operators/mysql_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ class MySqlOperator(BaseOperator):
@apply_defaults
def __init__(
self, sql, mysql_conn_id='mysql_default', parameters=None,
*args, **kwargs):
autocommit=False, *args, **kwargs):
super(MySqlOperator, self).__init__(*args, **kwargs)
self.mysql_conn_id = mysql_conn_id
self.sql = sql
self.autocommit = autocommit
self.parameters = parameters

def execute(self, context):
logging.info('Executing: ' + str(self.sql))
hook = MySqlHook(mysql_conn_id=self.mysql_conn_id)
hook.run(self.sql, parameters=self.parameters)
hook.run(
self.sql,
autocommit=self.autocommit,
parameters=self.parameters)

0 comments on commit 8d14662

Please sign in to comment.