This is an automated email from the ASF dual-hosted git repository.
Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 963acaecb2 fix(services/s3): normalize empty version IDs in batch
delete errors (#9072)
963acaecb2 is described below
commit 963acaecb2baf0e6cc1badc9ce6d25bb70c781f1
Author: Xuanwo <[email protected]>
AuthorDate: Wed Nov 25 21:35:52 2026 +0800
fix(services/s3): normalize empty version IDs in batch delete errors (#9072)
---
core/services/s3/src/core.rs | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/core/services/s3/src/core.rs b/core/services/s3/src/core.rs
index b3e1073d70..39958994eb 100644
--- a/core/services/s3/src/core.rs
+++ b/core/services/s3/src/core.rs
@@ -49,6 +49,7 @@ use reqsign_aws_v4::RequestSigner as AwsV4Signer;
use reqsign_aws_v4::S3ExpressSessionProvider;
use reqsign_core::{Context, ErrorKind as ReqsignErrorKind,
ProvideCredentialDyn, Signer};
use serde::Deserialize;
+use serde::Deserializer;
use serde::Serialize;
use opendal_core::raw::*;
@@ -1761,9 +1762,18 @@ pub struct DeleteObjectsResultError {
pub code: String,
pub key: String,
pub message: String,
+ #[serde(deserialize_with = "deserialize_delete_error_version_id")]
pub version_id: Option<String>,
}
+fn deserialize_delete_error_version_id<'de, D>(deserializer: D) ->
Result<Option<String>, D::Error>
+where
+ D: Deserializer<'de>,
+{
+ // Ceph RGW emits an empty VersionId element for unversioned delete errors.
+ Ok(Option::<String>::deserialize(deserializer)?.filter(|version|
!version.is_empty()))
+}
+
/// Output of ListBucket/ListObjects (a.k.a ListObjectsV1).
#[derive(Default, Debug, Deserialize)]
#[serde(default, rename_all = "PascalCase")]
@@ -2067,6 +2077,28 @@ mod tests {
assert_eq!(out.error[0].key, "sample2.txt");
assert_eq!(out.error[0].code, "AccessDenied");
assert_eq!(out.error[0].message, "Access Denied");
+ assert_eq!(out.error[0].version_id, None);
+ }
+
+ #[test]
+ fn test_deserialize_delete_objects_error_version_id() {
+ for (version_xml, expected) in [
+ ("<VersionId></VersionId>", None),
+ ("<VersionId/>", None),
+ ("<VersionId>null</VersionId>", Some("null")),
+ ("<VersionId>abc123</VersionId>", Some("abc123")),
+ ] {
+ let xml = format!(
+ "<DeleteResult><Error><Key>sample.txt</Key>{version_xml}\
+ <Code>PreconditionFailed</Code></Error></DeleteResult>"
+ );
+ let result: DeleteObjectsResult =
quick_xml::de::from_str(&xml).expect("must succeed");
+ assert_eq!(
+ result.error[0].version_id.as_deref(),
+ expected,
+ "{version_xml}"
+ );
+ }
}
/// This example is from
https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjects.html#API_ListObjects_Examples