From 11a719e611a674642ea407730c488b2c1a4df0e1 Mon Sep 17 00:00:00 2001 From: Keshav Mohta <68001229+keshavmohta09@users.noreply.github.com> Date: Fri, 12 Sep 2025 23:08:34 +0530 Subject: [PATCH] Fixes: Oracle Stored Packages Test Connection Step #23370 --- .../source/database/oracle/connection.py | 20 ++---------- .../source/database/oracle/queries.py | 31 +++++++++++++++---- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/ingestion/src/metadata/ingestion/source/database/oracle/connection.py b/ingestion/src/metadata/ingestion/source/database/oracle/connection.py index 77f44717224..6f5db0227b7 100644 --- a/ingestion/src/metadata/ingestion/source/database/oracle/connection.py +++ b/ingestion/src/metadata/ingestion/source/database/oracle/connection.py @@ -48,8 +48,7 @@ from metadata.ingestion.connections.test_connections import test_connection_db_c from metadata.ingestion.ometa.ometa_api import OpenMetadata from metadata.ingestion.source.database.oracle.queries import ( CHECK_ACCESS_TO_ALL, - ORACLE_GET_SCHEMA, - ORACLE_GET_STORED_PACKAGES, + TEST_ORACLE_GET_STORED_PACKAGES, ) from metadata.utils.constants import THREE_MIN from metadata.utils.logger import ingestion_logger @@ -97,18 +96,9 @@ class OracleConnection(BaseConnection[OracleConnectionConfig, Engine]): of a metadata workflow or during an Automation Workflow """ - def test_oracle_package_access(engine): - try: - schema_name = engine.execute(ORACLE_GET_SCHEMA).scalar() - return ORACLE_GET_STORED_PACKAGES.format(schema=schema_name) - except Exception as e: - raise OraclePackageAccessError( - f"Failed to access Oracle stored packages: {e}" - ) - test_conn_queries = { "CheckAccess": CHECK_ACCESS_TO_ALL, - "PackageAccess": test_oracle_package_access(self.client), + "PackageAccess": TEST_ORACLE_GET_STORED_PACKAGES, } return test_connection_db_common( @@ -225,9 +215,3 @@ class OracleConnection(BaseConnection[OracleConnectionConfig, Engine]): return url raise ValueError(f"Unknown connection type {connection.oracleConnectionType}") - - -class OraclePackageAccessError(Exception): - """ - Raised when unable to access Oracle stored packages - """ diff --git a/ingestion/src/metadata/ingestion/source/database/oracle/queries.py b/ingestion/src/metadata/ingestion/source/database/oracle/queries.py index 2d5ae8bbcdb..622477dadd0 100644 --- a/ingestion/src/metadata/ingestion/source/database/oracle/queries.py +++ b/ingestion/src/metadata/ingestion/source/database/oracle/queries.py @@ -95,12 +95,7 @@ WHERE type = 'PROCEDURE' and owner = '{schema}' """ ) -ORACLE_GET_SCHEMA = """ - SELECT USERNAME AS SCHEMA_NAME - FROM ALL_USERS - WHERE ROWNUM = 1 - ORDER BY USERNAME -""" + ORACLE_GET_STORED_PACKAGES = textwrap.dedent( """ SELECT @@ -115,6 +110,30 @@ FROM WHERE TYPE IN ('PACKAGE', 'PACKAGE BODY') AND owner = '{schema}' """ ) + +TEST_ORACLE_GET_STORED_PACKAGES = textwrap.dedent( + """ +SELECT + OWNER, + NAME, + LINE, + TEXT, + 'StoredPackage' as procedure_type +FROM + DBA_SOURCE +WHERE + TYPE IN ('PACKAGE', 'PACKAGE BODY') + AND owner = ( + SELECT + USERNAME + FROM + ALL_USERS + WHERE + ROWNUM = 1 + ) +""" +) + CHECK_ACCESS_TO_ALL = "SELECT table_name FROM DBA_TABLES where ROWNUM < 2" ORACLE_GET_STORED_PROCEDURE_QUERIES = textwrap.dedent( """