Fix sql_warehouse_name resolution: handle 'warehouses' API response key#63286
Open
ataulmujeeb-cyber wants to merge 2 commits intoapache:mainfrom
Open
Fix sql_warehouse_name resolution: handle 'warehouses' API response key#63286ataulmujeeb-cyber wants to merge 2 commits intoapache:mainfrom
ataulmujeeb-cyber wants to merge 2 commits intoapache:mainfrom
Conversation
… SQL endpoints"
The _get_sql_endpoint_by_name method calls GET /api/2.0/sql/warehouses
(the current API path) but checks for the "endpoints" key in the
response. Since Databricks renamed SQL endpoints to SQL warehouses,
the current API returns data under the "warehouses" key, causing the
check to always fail.
This fix handles both the current ("warehouses") and legacy
("endpoints") response keys for backward compatibility.
Closes: apache#63285
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
|
providers/databricks/src/airflow/providers/databricks/hooks/databricks_sql.py
Outdated
Show resolved
Hide resolved
Replace AirflowException with standard Python exceptions per contributing guidelines: - RuntimeError for unexpected API response (no warehouses/endpoints key) - ValueError for warehouse name not found in results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #63285
The
_get_sql_endpoint_by_namemethod inDatabricksSqlHookfails withAirflowException: Can't list Databricks SQL endpointswheneversql_warehouse_name(orsql_endpoint_name) is used instead ofhttp_path.Root Cause
The
LIST_SQL_ENDPOINTS_ENDPOINTconstant was updated to use the current Databricks API path (GET /api/2.0/sql/warehouses), but the response parsing in_get_sql_endpoint_by_namestill checks for the legacy"endpoints"key. The current API returns data under"warehouses":GET /api/2.0/sql/endpoints(legacy)"endpoints"GET /api/2.0/sql/warehouses(current)"warehouses"Since the code calls the new path but checks for the old key, the condition
if "endpoints" not in resultis alwaysTrue, and the method always raises an exception.Fix
Updated
_get_sql_endpoint_by_nameto check for both"warehouses"(current) and"endpoints"(legacy) response keys:This ensures backward compatibility if any Databricks workspace still returns the legacy format.
Changes
providers/databricks/src/airflow/providers/databricks/hooks/databricks_sql.py: Updated_get_sql_endpoint_by_nameto handle both"warehouses"and"endpoints"response keysproviders/databricks/tests/unit/databricks/hooks/test_databricks_sql.py:"warehouses"response formatTestGetSqlEndpointByNametest class with 4 tests covering:"warehouses"key)"endpoints"key)Affected Components
This bug affects all operators and sensors that use
sql_warehouse_name/sql_endpoint_name:DatabricksSqlSensorDatabricksPartitionSensorDatabricksSqlOperatorDatabricksSqlHookwithsql_endpoint_nameVersions Tested
apache-airflow-providers-databricks==7.9.1Workaround (for users on affected versions)
Use
http_pathdirectly instead ofsql_warehouse_name: