Skip to content

Commit db81c27

Browse files
authored
Merge pull request #114 from oracle/bugfix/110
Bugfix/110
2 parents bba0da9 + cba22ab commit db81c27

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

dbt/adapters/oracle/connections.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import enum
2222
import time
2323
import uuid
24+
import platform
2425

2526
import dbt.exceptions
2627
from dbt.adapters.base import Credentials
@@ -113,6 +114,9 @@ class OracleAdapterCredentials(Credentials):
113114
# Base URL for ADB-S OML REST API
114115
oml_cloud_service_url: Optional[str] = None
115116

117+
# session info is stored in v$session for each dbt run
118+
session_info: Optional[Dict[str, str]] = field(default_factory=dict)
119+
116120

117121
_ALIASES = {
118122
'dbname': 'database',
@@ -137,7 +141,8 @@ def _connection_keys(self) -> Tuple[str]:
137141
'service', 'connection_string',
138142
'shardingkey', 'supershardingkey',
139143
'cclass', 'purity', 'retry_count',
140-
'retry_delay', 'oml_cloud_service_url'
144+
'retry_delay', 'oml_cloud_service_url',
145+
'session_info'
141146
)
142147

143148
@classmethod
@@ -175,6 +180,20 @@ def get_dsn(self) -> str:
175180
class OracleAdapterConnectionManager(SQLConnectionManager):
176181
TYPE = 'oracle'
177182

183+
@staticmethod
184+
def get_session_info(credentials):
185+
default_action = "DBT RUN"
186+
default_client_identifier = f'dbt-oracle-client-{uuid.uuid4()}'
187+
default_client_info = "_".join([platform.node(), platform.machine()])
188+
default_module = f'dbt-{dbt_version}'
189+
return {
190+
"action": credentials.session_info.get("action", default_action),
191+
"client_identifier": credentials.session_info.get("client_identifier", default_client_identifier),
192+
"clientinfo": credentials.session_info.get("client_info", default_client_info),
193+
"module": credentials.session_info.get("module", default_module)
194+
}
195+
196+
178197
@classmethod
179198
def open(cls, connection):
180199
if connection.state == 'open':
@@ -219,15 +238,14 @@ def open(cls, connection):
219238

220239
try:
221240
handle = oracledb.connect(**conn_config)
222-
# client_identifier and module are saved in corresponding columns in v$session
223-
action = "dbt run"
224-
client_identifier = f'dbt-oracle-client-{uuid.uuid4()}'
225-
module = f'dbt-{dbt_version}'
226-
client_info = {"action": action, "client_identifier": client_identifier, "module": module}
227-
logger.info(f"Session info :{json.dumps(client_info)}")
228-
handle.module = module
229-
handle.client_identifier = client_identifier
230-
handle.action = action
241+
# session_info is stored in v$session
242+
session_info = cls.get_session_info(credentials=credentials)
243+
logger.info(f"Session info :{json.dumps(session_info)}")
244+
for k, v in session_info.items():
245+
try:
246+
setattr(handle, k, v)
247+
except AttributeError:
248+
logger.warning(f"Python driver does not support setting {k}")
231249
connection.handle = handle
232250
connection.state = 'open'
233251
except oracledb.DatabaseError as e:

dbt_adbs_test_project/profiles.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ dbt_test:
1212
#database: "{{ env_var('DBT_ORACLE_DATABASE') }}"
1313
schema: "{{ env_var('DBT_ORACLE_SCHEMA') }}"
1414
oml_cloud_service_url: "{{ env_var('DBT_ORACLE_OML_CLOUD_SERVICE_URL')}}"
15+
session_info:
16+
action: "dbt run"
17+
client_identifier: "dbt-mac-abhisoms"
18+
client_info: "dbt Python3.9 thin driver"
19+
module: "dbt-module-1.5.2"
1520
retry_count: 1
1621
retry_delay: 5
1722
shardingkey:
@@ -42,6 +47,11 @@ dbt_test:
4247
database: "{{ env_var('DBT_ORACLE_DATABASE') }}"
4348
tns_name: "{{ env_var('DBT_ORACLE_TNS_NAME') }}"
4449
schema: "{{ env_var('DBT_ORACLE_SCHEMA') }}"
50+
session_info:
51+
action: "dbt run"
52+
client_identifier: "dbt-mac-abhisoms"
53+
client_info: "dbt Python3.9 thin driver"
54+
module: "dbt-module-1.5.2"
4555
shardingkey:
4656
- skey
4757
supershardingkey:

0 commit comments

Comments
 (0)