Skip to content

Commit

Permalink
Resolving mysql deprecated operator warnings (#39725)
Browse files Browse the repository at this point in the history
* Resolving mysql deprecated operator warnings

* Resolving mysql deprecated operator warnings

* Resolving mysql deprecated warnings

---------

Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
  • Loading branch information
dirrao and potiuk authored May 26, 2024
1 parent 8fbf466 commit e3c3175
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion airflow/providers/mysql/operators/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MySqlOperator(SQLExecuteQueryOperator):
.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:MySqlOperator`
:ref:`howto/operator:mysql`
:param sql: the sql code to be executed. Can receive a str representing a
sql statement, a list of str (sql statements), or reference to a template file.
Expand Down
14 changes: 8 additions & 6 deletions docs/apache-airflow-providers-mysql/operators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
.. _howto/operator:MySqlOperator:
.. _howto/operator:mysql:

MySqlOperator
=============
How-to Guide for Mysql using SQLExecuteQueryOperator
====================================================

Use the :class:`~airflow.providers.mysql.operators.MySqlOperator` to execute
Use the :class:`~airflow.providers.common.sql.operators.SQLExecuteQueryOperator` to execute
SQL commands in a `MySql <https://dev.mysql.com/doc/>`__ database.

.. warning::
Previously, MySqlOperator was used to perform this kind of operation. But at the moment MySqlOperator is deprecated and will be removed in future versions of the provider. Please consider to switch to SQLExecuteQueryOperator as soon as possible.

Using the Operator
^^^^^^^^^^^^^^^^^^

Use the ``mysql_conn_id`` argument to connect to your MySql instance where
Use the ``conn_id`` argument to connect to your MySql instance where
the connection metadata is structured as follows:

.. list-table:: MySql Airflow Connection Metadata
Expand All @@ -49,7 +51,7 @@ the connection metadata is structured as follows:
* - Port: int
- MySql port

An example usage of the MySqlOperator is as follows:
An example usage of the SQLExecuteQueryOperator is as follows:

.. exampleinclude:: /../../tests/system/providers/mysql/example_mysql.py
:language: python
Expand Down
1 change: 0 additions & 1 deletion tests/always/test_example_dags.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
# Deprecated Operators/Hooks, which replaced by common.sql Operators/Hooks
"tests/system/providers/apache/drill/example_drill_dag.py",
"tests/system/providers/microsoft/mssql/example_mssql.py",
"tests/system/providers/mysql/example_mysql.py",
"tests/system/providers/snowflake/example_snowflake.py",
"tests/system/providers/trino/example_trino.py",
)
Expand Down
8 changes: 4 additions & 4 deletions tests/system/providers/mysql/example_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@
from datetime import datetime

from airflow import DAG
from airflow.providers.mysql.operators.mysql import MySqlOperator
from airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator

ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
DAG_ID = "example_mysql"

with DAG(
DAG_ID,
start_date=datetime(2021, 1, 1),
default_args={"mysql_conn_id": "mysql_conn_id"},
default_args={"conn_id": "mysql_conn_id"},
tags=["example"],
catchup=False,
) as dag:
# [START howto_operator_mysql]

drop_table_mysql_task = MySqlOperator(
drop_table_mysql_task = SQLExecuteQueryOperator(
task_id="drop_table_mysql", sql=r"""DROP TABLE table_name;""", dag=dag
)

# [END howto_operator_mysql]

# [START howto_operator_mysql_external_file]

mysql_task = MySqlOperator(
mysql_task = SQLExecuteQueryOperator(
task_id="drop_table_mysql_external_file",
sql="/scripts/drop_table.sql",
dag=dag,
Expand Down

0 comments on commit e3c3175

Please sign in to comment.