karunpoudel commented on issue #44286:
URL: https://github.com/apache/airflow/issues/44286#issuecomment-2990242925
To recreate the issue:
```python
from airflow.decorators import dag, task
from airflow.hooks.base import BaseHook
@dag()
def example_azure():
def sdk_client(**kwargs):
pass
@task()
def test_hook():
print("Hello, Azure!")
conn = BaseHook.get_connection("azure_sp")
azure_hook = conn.get_hook(hook_params={"sdk_client": sdk_client})
print("Done")
test_hook()
example_azure()
```
Error log:
```
File "/usr/local/airflow/dags/example/example_azure.py", line 13, in
test_hook
azure_hook = conn.get_hook(hook_params={"sdk_client": sdk_client})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/usr/local/lib/python3.12/site-packages/airflow/models/connection.py", line
419, in get_hook
return hook_class(**{hook.connection_id_attribute_name: self.conn_id},
**hook_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: AzureBaseHook.__init__() got an unexpected keyword argument
'azure_conn_id'
```
Workaround:
Directly instantiate hook without using Connection.get_hook().
Since the hook has extra required parameter, we can't directly use the
simpler form `BaseHook.get_hook(conn_id)`. So this workaround might not be too
bad.
```python
@task()
def test_hook():
from airflow.providers.microsoft.azure.hooks.base_azure import
AzureBaseHook
print("Hello, Azure!")
azure_hook = AzureBaseHook(sdk_client, "azure_sp")
print("Done")
```
Might be useful to fix the issue just for completeness.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]