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
8 changes: 4 additions & 4 deletions providers/oracle/src/airflow/providers/oracle/hooks/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,11 @@ def get_uri(self) -> str:
if sid and service_name:
raise ValueError("At most one allowed for 'sid', and 'service name'.")

uri = f"oracle://{login}:{password}@{host}:{port}"
if sid:
uri = f"oracle+oracledb://{login}:{password}@{host}:{port}"
if service_name:
uri = f"{uri}?service_name={service_name}"
elif sid:
uri = f"{uri}/{sid}"
elif service_name:
uri = f"{uri}/{service_name}"
elif conn.schema:
uri = f"{uri}/{conn.schema}"

Expand Down
21 changes: 6 additions & 15 deletions providers/oracle/tests/unit/oracle/hooks/test_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,43 +270,34 @@ def test_type_checking_thick_mode_config_dir(self):
[
pytest.param(
{"extra": '{"service_name": "service"}', "schema": None, "port": 1521},
"oracle://login:password@host:1521/service",
"oracle+oracledb://login:password@host:1521?service_name=service",
id="service_name_in_extra",
),
pytest.param(
{"extra": '{"sid": "sid"}', "schema": None, "port": 1521},
"oracle://login:password@host:1521/sid",
"oracle+oracledb://login:password@host:1521/sid",
id="sid_in_extra",
),
pytest.param(
{"extra": "{}", "schema": "db_schema", "port": 1521},
"oracle://login:password@host:1521/db_schema",
"oracle+oracledb://login:password@host:1521/db_schema",
id="schema_only",
),
pytest.param(
{"extra": "{}", "schema": None, "port": 1521},
"oracle://login:password@host:1521",
"oracle+oracledb://login:password@host:1521",
id="no_schema_no_extra",
),
pytest.param(
{"extra": "{}", "schema": "db_schema", "port": None},
"oracle://login:password@host:1521/db_schema",
"oracle+oracledb://login:password@host:1521/db_schema",
id="schema_only_default_port",
),
pytest.param(
{"extra": '{"service_name": "service"}', "schema": "db_schema", "port": 1521},
"oracle://login:password@host:1521/service",
"oracle+oracledb://login:password@host:1521?service_name=service",
id="service_name_with_schema",
),
pytest.param(
{
"extra": '{"service_name": "(DESCRIPTION=(ADDRESS=(host=oracle://somedb.example.com)(protocol=TCP)(port=1521))(CONNECT_DATA=(SERVICE_NAME=orclpdb)))"}',
"schema": None,
"port": 1521,
},
"oracle://login:password@host:1521/(DESCRIPTION=(ADDRESS=(host=oracle://somedb.example.com)(protocol=TCP)(port=1521))(CONNECT_DATA=(SERVICE_NAME=orclpdb)))",
id="complex_service_name",
),
],
)
@mock.patch("airflow.providers.oracle.hooks.oracle.oracledb.connect")
Expand Down