From e2a4936c4ac2c28e96d4072f9c100d7f440ea40a Mon Sep 17 00:00:00 2001 From: Hussein Awala Date: Sun, 17 Sep 2023 01:58:10 +0200 Subject: [PATCH 1/2] Consolidate hook management in AzureDataExplorerQueryOperator --- airflow/providers/microsoft/azure/operators/adx.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/airflow/providers/microsoft/azure/operators/adx.py b/airflow/providers/microsoft/azure/operators/adx.py index babf38c038eb0..23fb62fe946ce 100644 --- a/airflow/providers/microsoft/azure/operators/adx.py +++ b/airflow/providers/microsoft/azure/operators/adx.py @@ -18,8 +18,11 @@ """This module contains Azure Data Explorer operators.""" from __future__ import annotations +from functools import cached_property from typing import TYPE_CHECKING, Sequence +from deprecated.classic import deprecated + from airflow.configuration import conf from airflow.models import BaseOperator from airflow.providers.microsoft.azure.hooks.adx import AzureDataExplorerHook @@ -61,10 +64,16 @@ def __init__( self.options = options self.azure_data_explorer_conn_id = azure_data_explorer_conn_id - def get_hook(self) -> AzureDataExplorerHook: + @cached_property + def hook(self) -> AzureDataExplorerHook: """Returns new instance of AzureDataExplorerHook.""" return AzureDataExplorerHook(self.azure_data_explorer_conn_id) + @deprecated(reason="use `hook` property instead.") + def get_hook(self) -> AzureDataExplorerHook: + """Returns new instance of AzureDataExplorerHook.""" + return self.hook + def execute(self, context: Context) -> KustoResultTable | str: """ Run KQL Query on Azure Data Explorer (Kusto). @@ -73,8 +82,7 @@ def execute(self, context: Context) -> KustoResultTable | str: https://docs.microsoft.com/en-us/azure/kusto/api/rest/response2 """ - hook = self.get_hook() - response = hook.run_query(self.query, self.database, self.options) + response = self.hook.run_query(self.query, self.database, self.options) if conf.getboolean("core", "enable_xcom_pickling"): return response.primary_results[0] else: From c7a7fe4bfe3e6536086744b931b2f374e3e6fc38 Mon Sep 17 00:00:00 2001 From: Hussein Awala Date: Sun, 17 Sep 2023 12:41:43 +0200 Subject: [PATCH 2/2] use AirflowProviderDeprecationWarning --- airflow/providers/microsoft/azure/operators/adx.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/airflow/providers/microsoft/azure/operators/adx.py b/airflow/providers/microsoft/azure/operators/adx.py index 23fb62fe946ce..630c6d497b377 100644 --- a/airflow/providers/microsoft/azure/operators/adx.py +++ b/airflow/providers/microsoft/azure/operators/adx.py @@ -24,6 +24,7 @@ from deprecated.classic import deprecated from airflow.configuration import conf +from airflow.exceptions import AirflowProviderDeprecationWarning from airflow.models import BaseOperator from airflow.providers.microsoft.azure.hooks.adx import AzureDataExplorerHook @@ -69,7 +70,7 @@ def hook(self) -> AzureDataExplorerHook: """Returns new instance of AzureDataExplorerHook.""" return AzureDataExplorerHook(self.azure_data_explorer_conn_id) - @deprecated(reason="use `hook` property instead.") + @deprecated(reason="use `hook` property instead.", category=AirflowProviderDeprecationWarning) def get_hook(self) -> AzureDataExplorerHook: """Returns new instance of AzureDataExplorerHook.""" return self.hook