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


##########
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
+        scope = conf.get("postgres", "azure_oauth_scope", 
fallback=self.default_azure_oauth_scope)
+        token = azure_base_hook.get_token(scope).token

Review Comment:
   Makes sense, thanks for clarifying that, keeping them separate sounds right, 
given the scope differences. Maybe later, we can still extract a small utility 
if more providers need similar handling.



##########
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:
   Got it, that makes sense. Thanks for explaining the flow! The 
AirflowOptionalProviderFeatureException is a good call here, clearer and more 
aligned with Airflow patterns.



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