Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@
Create sqlalchemy connection
"""

if not connection.connectionArguments:
connection.connectionArguments = init_empty_connection_arguments()

if connection.httpPath:
if not connection.connectionArguments:
connection.connectionArguments = init_empty_connection_arguments()
connection.connectionArguments.root["http_path"] = connection.httpPath
Comment thread
mohittilala marked this conversation as resolved.

Comment thread
mohittilala marked this conversation as resolved.
auth_args = get_auth_config(connection)
Expand Down Expand Up @@ -160,7 +161,7 @@
engine = get_sqlalchemy_connection(service_connection)
with engine.connect() as connection: # noqa: PLR1704
connection.execute(
text(UNITY_CATALOG_GET_CATALOGS_TAGS.format(database=table_obj.catalog_name).replace(";", " limit 1;"))

Check failure on line 164 in ingestion/src/metadata/ingestion/source/database/unitycatalog/connection.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Define a constant instead of duplicating this literal " limit 1;" 4 times.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ3d9KDiQKg3Fu1Wnya5&open=AZ3d9KDiQKg3Fu1Wnya5&pullRequest=27844
)
connection.execute(
text(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2025 Collate
# Licensed under the Collate Community License, Version 1.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/LICENSE
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Tests for unitycatalog.connection.get_sqlalchemy_connection.
"""

from sqlalchemy.engine import Engine

from metadata.generated.schema.entity.services.connections.database.databricks.personalAccessToken import (
PersonalAccessToken,
)
from metadata.generated.schema.entity.services.connections.database.unityCatalogConnection import (
UnityCatalogConnection,
)
from metadata.ingestion.source.database.unitycatalog.connection import (
get_sqlalchemy_connection,
)


def _connection(**overrides) -> UnityCatalogConnection:
defaults = {
"hostPort": "test-host:443",
"authType": PersonalAccessToken(token="test-token"),
}
defaults.update(overrides)
return UnityCatalogConnection(**defaults)


def test_returns_engine_when_http_path_and_connection_args_are_unset():
"""
Regression for the AttributeError raised on
`connection.connectionArguments.root.update(auth_args)` when both
httpPath and connectionArguments are omitted from the service config.
"""
connection = _connection()
assert connection.httpPath is None
assert connection.connectionArguments is None

engine = get_sqlalchemy_connection(connection)

assert isinstance(engine, Engine)
Comment thread
mohittilala marked this conversation as resolved.


def test_returns_engine_when_http_path_is_set():
"""Engine is created and http_path is accepted as a connect arg."""
connection = _connection(httpPath="/sql/1.0/warehouses/abc")

engine = get_sqlalchemy_connection(connection)

assert isinstance(engine, Engine)
assert engine.url.host == "test-host"
Loading