ataulmujeeb-cyber commented on code in PR #63286:
URL: https://github.com/apache/airflow/pull/63286#discussion_r2915187264


##########
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:
   Hi @justinpakzad,
   
   Thank you for the review and the pointer to the contributing guidelines! 
Great call! I have updated the PR to use standard Python exceptions instead of 
AirflowException: 
   
   RuntimeError for when the API response contains neither warehouses nor 
endpoints key (unexpected API response)
                                                                                
         
   ValueError for when the specified warehouse name doesn't match any warehouse 
in the results 
   
   I also took the opportunity to make the RuntimeError message more 
descriptive and actionable, it  now mentions the missing keys and suggests 
checking permissions. 
   
   The updated commit is e269483. 
   
   Please let me know if there's anything else I should adjust!



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