diff --git a/airflow/providers/microsoft/azure/operators/adx.py b/airflow/providers/microsoft/azure/operators/adx.py index babf38c038eb0..630c6d497b377 100644 --- a/airflow/providers/microsoft/azure/operators/adx.py +++ b/airflow/providers/microsoft/azure/operators/adx.py @@ -18,9 +18,13 @@ """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.exceptions import AirflowProviderDeprecationWarning from airflow.models import BaseOperator from airflow.providers.microsoft.azure.hooks.adx import AzureDataExplorerHook @@ -61,10 +65,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.", category=AirflowProviderDeprecationWarning) + 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 +83,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: