From e3c31752f180ae60f0c0de304793018084e02943 Mon Sep 17 00:00:00 2001 From: Gopal Dirisala <39794726+dirrao@users.noreply.github.com> Date: Sun, 26 May 2024 19:41:31 +0530 Subject: [PATCH] Resolving mysql deprecated operator warnings (#39725) * Resolving mysql deprecated operator warnings * Resolving mysql deprecated operator warnings * Resolving mysql deprecated warnings --------- Co-authored-by: Jarek Potiuk --- airflow/providers/mysql/operators/mysql.py | 2 +- docs/apache-airflow-providers-mysql/operators.rst | 14 ++++++++------ tests/always/test_example_dags.py | 1 - tests/system/providers/mysql/example_mysql.py | 8 ++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/airflow/providers/mysql/operators/mysql.py b/airflow/providers/mysql/operators/mysql.py index ab423ef91b90..2c2436b4d9da 100644 --- a/airflow/providers/mysql/operators/mysql.py +++ b/airflow/providers/mysql/operators/mysql.py @@ -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. diff --git a/docs/apache-airflow-providers-mysql/operators.rst b/docs/apache-airflow-providers-mysql/operators.rst index 605e38fb85a4..2ee7b885cd7b 100644 --- a/docs/apache-airflow-providers-mysql/operators.rst +++ b/docs/apache-airflow-providers-mysql/operators.rst @@ -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 `__ 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 @@ -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 diff --git a/tests/always/test_example_dags.py b/tests/always/test_example_dags.py index 7d2ec685f8df..d58f58d6f1b2 100644 --- a/tests/always/test_example_dags.py +++ b/tests/always/test_example_dags.py @@ -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", ) diff --git a/tests/system/providers/mysql/example_mysql.py b/tests/system/providers/mysql/example_mysql.py index 7327d095f290..0874e24b4bc7 100644 --- a/tests/system/providers/mysql/example_mysql.py +++ b/tests/system/providers/mysql/example_mysql.py @@ -25,7 +25,7 @@ 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" @@ -33,13 +33,13 @@ 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 ) @@ -47,7 +47,7 @@ # [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,