Skip to content

Commit f33d06d

Browse files
aakash-saravanan-dbIsaac
andcommitted
fix(volume): close before failing execute_update and keep binding errors uniform
ADBC execute_update closes the statement before reporting a missing staging option. PyO3 KernelError always carries local_os_error and local_path, None when absent. kernel_executed_statement_is_volume_operation runs inside catch_ffi like the other entry points. Two new tests move above the doc comments of the items they precede. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
1 parent 92da947 commit f33d06d

6 files changed

Lines changed: 39 additions & 35 deletions

File tree

‎adbc/src/statement.rs‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -893,23 +893,22 @@ impl adbc_core::Statement for Statement {
893893
let Some(binding) = self.binding.take() else {
894894
if !self.enable_direct_results {
895895
let (executed, stream) = self.execute_async_inner()?;
896-
require_volume_options(stream.is_volume_operation(), self.volume_options.as_ref())?;
896+
let marked = stream.is_volume_operation();
897897
let count = executed.num_modified_rows();
898898
drop(stream);
899899
self.runtime
900900
.block_on_safe(executed.close())
901901
.map_err(map_kernel_error)?;
902+
require_volume_options(marked, self.volume_options.as_ref())?;
902903
return Ok(count);
903904
}
904905
let executed = self.execute_inner()?;
905-
require_volume_options(
906-
executed.result_stream().is_volume_operation(),
907-
self.volume_options.as_ref(),
908-
)?;
906+
let marked = executed.result_stream().is_volume_operation();
909907
let count = executed.num_modified_rows();
910908
self.runtime
911909
.block_on_safe(executed.close())
912910
.map_err(map_kernel_error)?;
911+
require_volume_options(marked, self.volume_options.as_ref())?;
913912
return Ok(count);
914913
};
915914

‎napi/src/database.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,8 +932,6 @@ pub async fn open_session(mut options: ConnectionOptions) -> napi::Result<Connec
932932
mod tests {
933933
use super::*;
934934

935-
/// Minimal options with only the required transport fields set;
936-
/// auth fields default to "absent" so each test sets what it needs.
937935
#[test]
938936
fn socket_timeout_also_limits_volume_transfers() {
939937
use std::time::Duration;
@@ -949,6 +947,8 @@ mod tests {
949947
}
950948
}
951949

950+
/// Minimal options with only the required transport fields set;
951+
/// auth fields default to "absent" so each test sets what it needs.
952952
fn base() -> ConnectionOptions {
953953
ConnectionOptions {
954954
host_name: "adb-1.azuredatabricks.net".to_owned(),

‎pyo3/src/errors.rs‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,13 @@ fn attach_attrs(
106106
}
107107

108108
/// A local file error also carries the OS error number and path, so the
109-
/// connector can raise the matching `OSError`.
109+
/// connector can raise the matching `OSError`; both are `None` otherwise.
110110
fn attach_local_error(
111111
bound: &Bound<'_, PyAny>,
112112
local: Option<&databricks_sql_kernel::LocalFileError>,
113113
) -> PyResult<()> {
114-
if let Some(local) = local {
115-
bound.setattr("local_os_error", local.raw_os_error)?;
116-
bound.setattr("local_path", local.path.as_str())?;
117-
}
118-
Ok(())
114+
bound.setattr("local_os_error", local.and_then(|local| local.raw_os_error))?;
115+
bound.setattr("local_path", local.map(|local| local.path.as_str()))
119116
}
120117

121118
/// Convert a kernel `Error` into a `KernelError` Python exception
@@ -197,7 +194,9 @@ pub(crate) fn closed_err(handle_name: &str) -> PyErr {
197194
None,
198195
None,
199196
None,
200-
) {
197+
)
198+
.and_then(|()| attach_local_error(bound.as_any(), None))
199+
{
201200
return setattr_err;
202201
}
203202
py_err

‎pyo3/tests/test_volume.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,8 @@ def test_local_file_errors_carry_the_os_error_and_path(tmp_path):
130130
assert raised.value.error_code == "VOLUME_LOCAL_FILE_ERROR"
131131
assert raised.value.local_os_error == errno.ENOENT
132132
assert raised.value.local_path == str(missing)
133+
executed.close()
134+
with pytest.raises(k.KernelError) as closed:
135+
executed.complete_volume_operation([str(tmp_path)], False)
136+
assert closed.value.local_os_error is None
137+
assert closed.value.local_path is None

‎src/c_abi/session.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,8 +2817,6 @@ mod tests {
28172817
}
28182818
}
28192819

2820-
/// A positive timeout is recorded in milliseconds; zero clears an earlier
2821-
/// override so the kernel default remains authoritative.
28222820
#[test]
28232821
fn set_storage_read_timeout_records_a_limit_or_no_limit() {
28242822
unsafe {
@@ -2839,6 +2837,8 @@ mod tests {
28392837
}
28402838
}
28412839

2840+
/// A positive timeout is recorded in milliseconds; zero clears an earlier
2841+
/// override so the kernel default remains authoritative.
28422842
#[test]
28432843
fn set_request_timeout_records_and_clears_override() {
28442844
unsafe {

‎src/c_abi/statement.rs‎

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -827,25 +827,26 @@ pub unsafe extern "C" fn kernel_executed_statement_is_volume_operation(
827827
exec: *const kernel_executed_statement_t,
828828
out: *mut bool,
829829
) -> KernelStatusCode {
830-
crate::c_abi::error::clear_error();
831-
let Some(handle) = (exec as *const ExecutedHandle).as_ref() else {
832-
return store_invalid_arg(
833-
"kernel_executed_statement_is_volume_operation: exec must not be null",
834-
);
835-
};
836-
if out.is_null() {
837-
return store_invalid_arg(
838-
"kernel_executed_statement_is_volume_operation: out must not be null",
839-
);
840-
}
841-
if !handle.exec.is_valid() {
842-
return store_and_code(Error::new(
843-
crate::kernel_error::ErrorCode::InvalidStatementHandle,
844-
"executed statement was invalidated by a re-execute or close on its parent statement",
845-
));
846-
}
847-
std::ptr::write(out, handle.exec.result_stream().is_volume_operation());
848-
KernelStatusCode::Success
830+
catch_ffi(|| {
831+
let Some(handle) = (exec as *const ExecutedHandle).as_ref() else {
832+
return store_invalid_arg(
833+
"kernel_executed_statement_is_volume_operation: exec must not be null",
834+
);
835+
};
836+
if out.is_null() {
837+
return store_invalid_arg(
838+
"kernel_executed_statement_is_volume_operation: out must not be null",
839+
);
840+
}
841+
if !handle.exec.is_valid() {
842+
return store_and_code(Error::new(
843+
crate::kernel_error::ErrorCode::InvalidStatementHandle,
844+
"executed statement was invalidated by a re-execute or close on its parent statement",
845+
));
846+
}
847+
std::ptr::write(out, handle.exec.result_stream().is_volume_operation());
848+
KernelStatusCode::Success
849+
})
849850
}
850851

851852
/// The server statement (query) id of a successfully executed statement, as a

0 commit comments

Comments
 (0)