justinpakzad commented on code in PR #63286:
URL: https://github.com/apache/airflow/pull/63286#discussion_r2915049724


##########
providers/databricks/src/airflow/providers/databricks/hooks/databricks_sql.py:
##########
@@ -120,12 +120,16 @@ def _get_extra_config(self) -> dict[str, Any | None]:
 
     def _get_sql_endpoint_by_name(self, endpoint_name) -> dict[str, Any]:
         result = self._do_api_call(LIST_SQL_ENDPOINTS_ENDPOINT)
-        if "endpoints" not in result:
-            raise AirflowException("Can't list Databricks SQL endpoints")
+        # The API response key depends on which endpoint path is used:
+        # - "warehouses" for the current /api/2.0/sql/warehouses path
+        # - "endpoints" for the legacy /api/2.0/sql/endpoints path
+        warehouses = result.get("warehouses") or result.get("endpoints")
+        if not warehouses:
+            raise AirflowException("Can't list Databricks SQL warehouses")
         try:
-            endpoint = next(endpoint for endpoint in result["endpoints"] if 
endpoint["name"] == endpoint_name)
+            endpoint = next(ep for ep in warehouses if ep["name"] == 
endpoint_name)
         except StopIteration:
-            raise AirflowException(f"Can't find Databricks SQL endpoint with 
name '{endpoint_name}'")
+            raise AirflowException(f"Can't find Databricks SQL warehouse with 
name '{endpoint_name}'")

Review Comment:
   I think we should favor standard Python exceptions here rather than using 
AirflowException. 
   
   One of the contributing docs has some more context on that: 
https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#dont-raise-airflowexception-directly



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