karunpoudel commented on code in PR #57184:
URL: https://github.com/apache/airflow/pull/57184#discussion_r2461116352


##########
providers/postgres/src/airflow/providers/postgres/hooks/postgres.py:
##########
@@ -522,19 +522,17 @@ def get_azure_iam_token(self, conn: Connection) -> 
tuple[str, str, int]:
             azure_conn = Connection.get(azure_conn_id)
         except AttributeError:
             azure_conn = Connection.get_connection_from_secrets(azure_conn_id) 
 # type: ignore[attr-defined]
-        azure_base_hook: AzureBaseHook = azure_conn.get_hook()
-        scope = conf.get("postgres", "azure_oauth_scope", 
fallback=self.default_azure_oauth_scope)
         try:
-            token = azure_base_hook.get_token(scope).token
-        except AttributeError as e:
-            if e.name == "get_token" and e.obj == azure_base_hook:
-                raise AttributeError(
-                    "'AzureBaseHook' object has no attribute 'get_token'. "
-                    "Please upgrade 
apache-airflow-providers-microsoft-azure>=12.8.0",
-                    name=e.name,
-                    obj=e.obj,
+            azure_base_hook: AzureBaseHook = azure_conn.get_hook()
+        except TypeError as e:
+            if "required positional argument: 'sdk_client'" in str(e):
+                raise TypeError(
+                    "Getting azure token is not supported by current version 
of 'AzureBaseHook'. "
+                    "Please upgrade 
apache-airflow-providers-microsoft-azure>=12.8.0"
                 ) from e
             raise

Review Comment:
   My original logic where we check for get_token was not reachable because it 
would fail first on `azure_conn.get_hook()` step since sdk_client was required 
argument in older version. So above update is to handle this error instead. I 
have updated it to raise `AirflowOptionalProviderFeatureException` exception, 
which might be more suitable for this scenario.



-- 
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]

Reply via email to