Skip to content

Commit 0fb6954

Browse files
authored
Fixes #27842: Fix unitycataog error when httpPath is missing (#27844)
* Fix unitycataog error when httpPath is missing * py_format * Drop redundant restoration test
1 parent ad9e1b7 commit 0fb6954

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

ingestion/src/metadata/ingestion/source/database/unitycatalog/connection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ def get_sqlalchemy_connection(connection: UnityCatalogConnection) -> Engine:
9292
Create sqlalchemy connection
9393
"""
9494

95+
if not connection.connectionArguments:
96+
connection.connectionArguments = init_empty_connection_arguments()
97+
9598
if connection.httpPath:
96-
if not connection.connectionArguments:
97-
connection.connectionArguments = init_empty_connection_arguments()
9899
connection.connectionArguments.root["http_path"] = connection.httpPath
99100

100101
auth_args = get_auth_config(connection)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2025 Collate
2+
# Licensed under the Collate Community License, Version 1.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
# https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/LICENSE
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS,
8+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
# See the License for the specific language governing permissions and
10+
# limitations under the License.
11+
12+
"""
13+
Tests for unitycatalog.connection.get_sqlalchemy_connection.
14+
"""
15+
16+
from sqlalchemy.engine import Engine
17+
18+
from metadata.generated.schema.entity.services.connections.database.databricks.personalAccessToken import (
19+
PersonalAccessToken,
20+
)
21+
from metadata.generated.schema.entity.services.connections.database.unityCatalogConnection import (
22+
UnityCatalogConnection,
23+
)
24+
from metadata.ingestion.source.database.unitycatalog.connection import (
25+
get_sqlalchemy_connection,
26+
)
27+
28+
29+
def _connection(**overrides) -> UnityCatalogConnection:
30+
defaults = {
31+
"hostPort": "test-host:443",
32+
"authType": PersonalAccessToken(token="test-token"),
33+
}
34+
defaults.update(overrides)
35+
return UnityCatalogConnection(**defaults)
36+
37+
38+
def test_returns_engine_when_http_path_and_connection_args_are_unset():
39+
"""
40+
Regression for the AttributeError raised on
41+
`connection.connectionArguments.root.update(auth_args)` when both
42+
httpPath and connectionArguments are omitted from the service config.
43+
"""
44+
connection = _connection()
45+
assert connection.httpPath is None
46+
assert connection.connectionArguments is None
47+
48+
engine = get_sqlalchemy_connection(connection)
49+
50+
assert isinstance(engine, Engine)
51+
52+
53+
def test_returns_engine_when_http_path_is_set():
54+
"""Engine is created and http_path is accepted as a connect arg."""
55+
connection = _connection(httpPath="/sql/1.0/warehouses/abc")
56+
57+
engine = get_sqlalchemy_connection(connection)
58+
59+
assert isinstance(engine, Engine)
60+
assert engine.url.host == "test-host"

0 commit comments

Comments
 (0)