Fix DatabricksSqlHook sqlalchemy_url missing http_path from connection extra - #69747
Conversation
|
Reviewers: @potiuk @kaxil (providers) + databricks maintainers. Fixes http_path not propagated to sqlalchemy_url. Fixes #69031 Drafted-by: Muse Spark 1.1; reviewed by @Vamsi-klu before posting |
|
Tested this PR branch locally in the Airflow UI with Breeze. Scenario exercised:
Result:
Screenshots are hosted on a dedicated assets-only branch in the fork. Connection Extra JSON configured Connection saved and filtered in the UI Scratch Dag run succeeded Task log showing Drafted-by: Codex (GPT-5.5) |
|
cc @moomindani |
|
@moomindani following up on the earlier UI-only/dummy-token validation, I also tested this PR branch against a real Databricks workspace connection through Breeze and the Airflow UI. This should give reviewers a real Databricks round-trip check for the Setup:
Result:
Task log evidence: Screenshots: Airflow connection filtered to the real Databricks workspace Successful Dag run Task log showing masked URI, No credentials are included in the screenshots or log excerpt. Drafted-by: Codex (GPT-5) |
…n extra get_conn correctly resolved http_path from explicit arg, sql_endpoint_name API, and extra_dejson, but sqlalchemy_url only used explicit arg. This caused get_uri() to return URL without http_path when connection defined via UI extra, breaking SQLAlchemy usage. Centralize resolution in _resolve_http_path helper, allow extra lookup in property without triggering API call. Add tests for extra path. Fixes: apache#69031
The SQLAlchemy URL path should be available from connection extras without changing the existing get_conn precedence for named SQL endpoints, so the resolution path needs explicit coverage for both behaviors.
4d452c8 to
fde316d
Compare
moomindani
left a comment
There was a problem hiding this comment.
Reviewed the updated revision (fde316d) and validated it against a real Databricks workspace with live SQL warehouse round-trips:
sqlalchemy_url/get_uri()resolvehttp_pathfrom the connection extra with zero API calls, and a live query over the resolved path succeeds (the #69031 fix).- An explicit
http_pathargument still wins over the extra. - Endpoint-name-only configuration: the property stays fully offline (no REST call — the regression flagged on #69037 is avoided), and
get_conn()then resolves via the warehouses API and connects. - With both
sql_endpoint_nameand an extrahttp_pathset,get_conn()still prefers the endpoint lookup (one API call) — precedence preserved vs main, confirmed live. Thanks for adding the second commit and the tests covering exactly this. - Existing and new unit tests pass locally (60 passed).
One tiny behavior diff I noticed, fine by me: an empty-string http_path in the connection extra used to be passed through to the connector; it now fails fast with the "http_path should be provided" error.
Two non-blocking inline notes below. LGTM.
Drafted-by: Claude Code (Fable 5); reviewed by @moomindani before posting
|
addressed both review notes from @moomindani, simplified the guard and added the docstring note. tests still pass. |
…fy guard Addressed review feedback on apache#69747. When both sql_endpoint_name and an http_path in the connection extra are set, sqlalchemy_url (which must stay offline) uses the extra value, while get_conn() prefers the named endpoint. This is intentional. - Added clarifying note to the _resolve_http_path docstring. - Simplified the now-redundant guard in get_conn() (the helper already handles the early return). The two tests that cover this exact scenario continue to pass. Refs: apache#69747
|
Verified the follow-up commit (c56cfcf) — both notes are addressed: the docstring now documents the Drafted-by: Claude Code (Fable 5); reviewed by @moomindani before posting |
…n extra (apache#69747) * Fix DatabricksSqlHook sqlalchemy_url missing http_path from connection extra get_conn correctly resolved http_path from explicit arg, sql_endpoint_name API, and extra_dejson, but sqlalchemy_url only used explicit arg. This caused get_uri() to return URL without http_path when connection defined via UI extra, breaking SQLAlchemy usage. Centralize resolution in _resolve_http_path helper, allow extra lookup in property without triggering API call. Add tests for extra path. Fixes: apache#69031 * Preserve Databricks SQL endpoint precedence The SQLAlchemy URL path should be available from connection extras without changing the existing get_conn precedence for named SQL endpoints, so the resolution path needs explicit coverage for both behaviors. * DatabricksSqlHook: document http_path precedence asymmetry and simplify guard Addressed review feedback on apache#69747. When both sql_endpoint_name and an http_path in the connection extra are set, sqlalchemy_url (which must stay offline) uses the extra value, while get_conn() prefers the named endpoint. This is intentional. - Added clarifying note to the _resolve_http_path docstring. - Simplified the now-redundant guard in get_conn() (the helper already handles the early return). The two tests that cover this exact scenario continue to pass. Refs: apache#69747 --------- Co-authored-by: probe <probe@example.com>







Problem
DatabricksSqlHook.sqlalchemy_urlandget_uri()did not includehttp_pathwhen that path was configured through the Databricks connection extra JSON. That is a common UI configuration path, and it made SQLAlchemy usage fail even thoughget_conn()could connect.What Changed
http_pathresolution for SQLAlchemy URL generation.sqlalchemy_urloffline-safe by allowing explicithttp_pathand connection-extrahttp_path, but not making a REST API call forsql_endpoint_name.get_conn()precedence: explicithttp_path, thensql_endpoint_name, then connection extra.Why The Follow-Up Commit Exists
The feedback was correct: the first helper implementation resolved connection extras before named SQL endpoints, which would have changed
get_conn()behavior. The follow-up keeps the SQLAlchemy fix while preserving the established connection precedence.Impact
http_pathlives in the Databricks connection extra.get_conn()continues to prefer a named SQL endpoint over connection-extrahttp_pathwhen both are provided.sqlalchemy_urldoes not perform a network/API lookup.Fixes: #69031
Testing
UV_CACHE_DIR=/tmp/uv-cache-69747-databricks uv run --python 3.11 --project providers/databricks ruff format providers/databricks/src/airflow/providers/databricks/hooks/databricks_sql.py providers/databricks/tests/unit/databricks/hooks/test_databricks_sql.pyUV_CACHE_DIR=/tmp/uv-cache-69747-databricks uv run --python 3.11 --project providers/databricks ruff check --fix providers/databricks/src/airflow/providers/databricks/hooks/databricks_sql.py providers/databricks/tests/unit/databricks/hooks/test_databricks_sql.pyAIRFLOW_HOME=/tmp/airflow-home-69747 UV_CACHE_DIR=/tmp/uv-cache-69747-databricks uv run --python 3.11 --project providers/databricks pytest providers/databricks/tests/unit/databricks/hooks/test_databricks_sql.py::test_sqlachemy_url_property providers/databricks/tests/unit/databricks/hooks/test_databricks_sql.py::test_get_conn_prefers_sql_endpoint_name_over_connection_extra_http_path providers/databricks/tests/unit/databricks/hooks/test_databricks_sql.py::test_sqlalchemy_url_uses_connection_extra_http_path_without_endpoint_lookup -xvs3 passed, 1 warningWas generative AI tooling used to co-author this PR?
Generated-by: Codex (GPT-5) following the guidelines
Drafted-by: Codex (GPT-5); reviewed by @Vamsi-klu before posting