Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(oracle): fall back when connection info is unsupported for native jobs (#13731) (#13748)

lxk95517936f5f0aac
diff --git a/crates/dbx-core/src/schema/native_jobs/mod.rs b/crates/dbx-core/src/schema/native_jobs/mod.rs
index 1ffb5dd080..33a84b4384 100644
--- a/crates/dbx-core/src/schema/native_jobs/mod.rs
+++ b/crates/dbx-core/src/schema/native_jobs/mod.rs
@@ -26,7 +26,7 @@ pub use operations::{
pub use references::{native_job_references_core, native_job_references_with};
pub use service::{
native_job_list_core, native_job_list_with, native_job_open_context_core, native_job_open_context_with,
- native_job_read_core, native_job_read_with, NativeJobRegistry, NativeJobRuntimeIdentity,
+ native_job_read_core, native_job_read_with, runtime_identity, NativeJobRegistry, NativeJobRuntimeIdentity,
};
pub type NativeJobCatalogRow = BTreeMap<String, Value>;
diff --git a/crates/dbx-core/src/schema/native_jobs/service.rs b/crates/dbx-core/src/schema/native_jobs/service.rs
index 45534a7573..693a2ab0fc 100644
--- a/crates/dbx-core/src/schema/native_jobs/service.rs
+++ b/crates/dbx-core/src/schema/native_jobs/service.rs
@@ -387,7 +387,7 @@ pub(super) async fn open_pool(
Ok((session, pool))
}
-async fn runtime_identity(
+pub async fn runtime_identity(
config: &ConnectionConfig,
pool: &PoolKind,
database: &str,
@@ -395,48 +395,61 @@ async fn runtime_identity(
runtime_identity_in_session(config, pool, database, None).await
}
-async fn runtime_identity_in_session(
+pub(super) async fn runtime_identity_in_session(
config: &ConnectionConfig,
pool: &PoolKind,
database: &str,
physical: Option<&NativeJobPhysicalSession>,
) -> Result<NativeJobRuntimeIdentity, &'static str> {
let timeout = super::super::agent_metadata_timeout(Some(config));
- let info = match pool {
+ let probed_info = match pool {
PoolKind::Agent(client) => {
if let Some(physical) = physical {
let mut params = serde_json::json!({});
physical.bind(&mut params);
- let value: Value = client
+ client
.lock()
.await
.call_typed_with_timeout("connection_info", params, timeout)
.await
- .map_err(|_| "native_job_runtime_identity_failed")?;
- database_info_from_protocol_value(&value)
+ .ok()
+ .and_then(|value| database_info_from_protocol_value(&value))
} else {
- client
- .lock()
- .await
- .connection_info(timeout)
- .await
- .map_err(|_| "native_job_runtime_identity_failed")?
- .database_info
+ client.lock().await.connection_info(timeout).await.ok().and_then(|info| info.database_info)
}
}
- PoolKind::ExternalDriver { config, session, .. } => {
- let mut params = serde_json::json!({ "connection": config.as_ref() });
+ PoolKind::ExternalDriver { config: driver_config, session, .. } => {
+ let mut params = serde_json::json!({ "connection": driver_config.as_ref() });
if let Some(physical) = physical {
physical.bind(&mut params);
}
- let value: Value = session
+ session
.invoke_with_timeout("connectionInfo", params, timeout)
.await
- .map_err(|_| "native_job_runtime_identity_failed")?;
- database_info_from_protocol_value(&value)
+ .ok()
+ .and_then(|value| database_info_from_protocol_value(&value))
}
_ => return Err("native_job_driver_route_missing"),
};
+ let info = match (probed_info, config.database_info.clone()) {
+ (Some(mut probed), Some(saved)) => {
+ if probed.product_name.is_none() {
+ probed.product_name = saved.product_name;
+ }
+ if probed.product_version.is_none() {
+ probed.product_version = saved.product_version;
+ }
+ if probed.current_database.is_none() {
+ probed.current_database = saved.current_database;
+ }
+ if probed.compatibility_mode.is_none() {
+ probed.compatibility_mode = saved.compatibility_mode;
+ }
+ Some(probed)
+ }
+ (Some(probed), None) => Some(probed),
+ (None, saved) => saved,
+ };
let engine = resolve_engine(config, info.as_ref())?;
let query = NativeJobCatalogQuery {
source: "session-user",
diff --git a/crates/dbx-core/tests/native_job_configuration_transport.rs b/crates/dbx-core/tests/native_job_configuration_transport.rs
index 759fcbb081..5cb52be86b 100644
--- a/crates/dbx-core/tests/native_job_configuration_transport.rs
+++ b/crates/dbx-core/tests/native_job_configuration_transport.rs
@@ -2,6 +2,7 @@
use dbx_core::connection::{task_client_session_id, AppState, PoolKind};
use dbx_core::db::agent_driver::{AgentDriverClient, AgentLaunchSpec, PooledAgentClient};
+use dbx_core::models::connection::{ConnectionConfig, DatabaseConnectionInfo};
use dbx_core::schema::native_jobs::*;
use dbx_types::native_jobs::*;
use serde_json::{json, Value};
@@ -46,6 +47,8 @@ fn native_job_configuration_rpc_fixture() {
|| (params["nativeJobOperationId"] == operation && params["nativeJobSessionToken"] == token);
let value = if !authorized {
json!({"jsonrpc":"2.0","id":request["id"],"error":{"code":-32000,"message":"fixture requires owned physical token"}})
+ } else if method == "connection_info" && mode == "oracle-no-connection-info" {
+ json!({"jsonrpc":"2.0","id":request["id"],"error":{"code":-32601,"message":"unknown method: connection_info"}})
} else {
let result = match method {
"handshake" => json!({"protocolVersion":2,"agentProtocolVersion":2,
@@ -75,10 +78,14 @@ fn native_job_configuration_rpc_fixture() {
"execute_query" => {
let sql = params["sql"].as_str().unwrap();
if sql == "SELECT USER AS DBX_SESSION_USER FROM DUAL" {
- query_result(
- &["DBX_SESSION_USER"],
- json!([[if leased && mode == "changed-user" { "Other" } else { "Owner" }]]),
- )
+ if mode == "oracle-query-failed" {
+ json!({"columns":[],"rows":[],"execution_error":true,"error":{"diagnostics":{"category":"sql","vendorCode":942}}})
+ } else {
+ query_result(
+ &["DBX_SESSION_USER"],
+ json!([[if leased && mode == "changed-user" { "Other" } else { "Owner" }]]),
+ )
+ }
} else if sql.starts_with("DECLARE") {
if sql.contains("SP_ENABLE_JOB('Job_1', 0)") {
enabled = false;
@@ -267,3 +274,89 @@ async fn production_rejects_changed_database_or_version_on_the_reserved_physical
.any(|request| request["params"]["sql"].as_str().is_some_and(|sql| sql.starts_with("DECLARE"))));
}
}
+
+#[tokio::test]
+async fn oracle_runtime_identity_falls_back_when_agent_connection_info_is_unsupported() {
+ let dir = tempfile::tempdir().unwrap();
+ let log = dir.path().join("requests.jsonl");
+ let storage = dbx_core::persistence::test_storage::open(&dir.path().join("state.db")).await.unwrap();
+ let state = Arc::new(AppState::new_with_plugin_and_agent_dir_and_app_version(
+ storage,
+ dir.path().join("plugins"),
+ dir.path().join("agents"),
+ "test",
+ ));
+ let saved_info = DatabaseConnectionInfo {
+ product_name: Some("Oracle Database".into()),
+ product_version: Some("11.2.0.4.0".into()),
+ current_database: Some("ORCL".into()),
+ ..Default::default()
+ };
+ let mut config: ConnectionConfig = serde_json::from_value(json!({
+ "id": "oracle-conn", "name": "Oracle fixture", "db_type": "oracle", "host": "127.0.0.1", "port": 1521,
+ "username": "Owner", "password": "", "database": ""
+ }))
+ .unwrap();
+ config.database_info = Some(saved_info.clone());
+ state.configs.write().await.insert("oracle-conn".into(), config.clone());
+
+ let launch = AgentLaunchSpec::new(std::env::current_exe().unwrap())
+ .with_args(["--exact", "native_job_configuration_rpc_fixture", "--nocapture", "--test-threads=1"])
+ .with_env(vec![
+ ("DBX_NATIVE_JOB_RPC_LOG".into(), log.to_string_lossy().into_owned()),
+ ("DBX_NATIVE_JOB_RPC_MODE".into(), "oracle-no-connection-info".into()),
+ ]);
+ let mut client = AgentDriverClient::spawn(launch).await.unwrap();
+ assert!(client.try_optional_handshake("test").await.is_some());
+ let client = Arc::new(PooledAgentClient::new(client));
+ let pool = PoolKind::Agent(client.clone());
+
+ let identity = match runtime_identity(&config, &pool, "").await {
+ Ok(identity) => identity,
+ Err(err) => panic!("expected success, got {err}"),
+ };
+ assert_eq!(identity.session_user, "Owner");
+ assert_eq!(identity.database_info, Some(saved_info));
+
+ client.lock().await.shutdown().await;
+ state.shutdown(Duration::from_secs(2)).await;
+}
+
+#[tokio::test]
+async fn oracle_runtime_identity_reports_failure_when_session_user_query_fails() {
+ let dir = tempfile::tempdir().unwrap();
+ let log = dir.path().join("requests.jsonl");
+ let storage = dbx_core::persistence::test_storage::open(&dir.path().join("state.db")).await.unwrap();
+ let state = Arc::new(AppState::new_with_plugin_and_agent_dir_and_app_version(
+ storage,
+ dir.path().join("plugins"),
+ dir.path().join("agents"),
+ "test",
+ ));
+ let config: ConnectionConfig = serde_json::from_value(json!({
+ "id": "oracle-conn", "name": "Oracle fixture", "db_type": "oracle", "host": "127.0.0.1", "port": 1521,
+ "username": "Owner", "password": "", "database": ""
+ }))
+ .unwrap();
+ state.configs.write().await.insert("oracle-conn".into(), config.clone());
+
+ let launch = AgentLaunchSpec::new(std::env::current_exe().unwrap())
+ .with_args(["--exact", "native_job_configuration_rpc_fixture", "--nocapture", "--test-threads=1"])
+ .with_env(vec![
+ ("DBX_NATIVE_JOB_RPC_LOG".into(), log.to_string_lossy().into_owned()),
+ ("DBX_NATIVE_JOB_RPC_MODE".into(), "oracle-query-failed".into()),
+ ]);
+ let mut client = AgentDriverClient::spawn(launch).await.unwrap();
+ assert!(client.try_optional_handshake("test").await.is_some());
+ let client = Arc::new(PooledAgentClient::new(client));
+ let pool = PoolKind::Agent(client.clone());
+
+ let err = match runtime_identity(&config, &pool, "").await {
+ Ok(_) => panic!("expected failure"),
+ Err(err) => err,
+ };
+ assert_eq!(err, "native_job_runtime_identity_failed");
+
+ client.lock().await.shutdown().await;
+ state.shutdown(Duration::from_secs(2)).await;
+}
diff --git a/crates/dbx-core/tests/native_job_service.rs b/crates/dbx-core/tests/native_job_service.rs
index c6fcee5e7d..199f32ae1d 100644
--- a/crates/dbx-core/tests/native_job_service.rs
+++ b/crates/dbx-core/tests/native_job_service.rs
@@ -628,6 +628,19 @@ async fn a_configuration_change_during_identity_read_cannot_issue_a_context() {
assert!(matches!(opened, Err("native_job_context_changed")));
}
+#[tokio::test]
+async fn oracle_context_opens_successfully_without_database_info() {
+ let (_directory, state) = state("oracle").await;
+ let ctx = native_job_open_context_with(&state, "connection", "", |_| {
+ std::future::ready(Ok(NativeJobRuntimeIdentity { database_info: None, session_user: "SYSTEM".into() }))
+ })
+ .await
+ .unwrap();
+ assert_eq!(ctx.engine, NativeJobEngine::Oracle);
+ assert_eq!(ctx.session_user, "SYSTEM");
+ assert!(ctx.product_version.is_none());
+}
+
#[tokio::test]
async fn runtime_engine_discovery_does_not_assume_oceanbase_means_oracle_mode() {
let (_directory, state) = state("jdbc").await;