From 3dc9dcbed19fa4f5014482fd3691f961ac6e453e Mon Sep 17 00:00:00 2001 From: zhuxiaolong37 Date: Wed, 5 Nov 2025 16:50:18 +0800 Subject: [PATCH 1/3] Delete Multiple Objects adds delete parameter --- alibabacloud_oss_v2/models/object_basic.py | 66 +++++- alibabacloud_oss_v2/serde_utils.py | 54 +++-- sample/delete_multiple_objects.py | 22 ++ tests/integration/test_client.py | 76 +++++++ tests/integration/test_object_basic_async.py | 76 +++++++ tests/unit/models/test_object_basic.py | 205 ++++++++++++++++++- 6 files changed, 484 insertions(+), 15 deletions(-) diff --git a/alibabacloud_oss_v2/models/object_basic.py b/alibabacloud_oss_v2/models/object_basic.py index 3ad5e94..02eee6e 100644 --- a/alibabacloud_oss_v2/models/object_basic.py +++ b/alibabacloud_oss_v2/models/object_basic.py @@ -1043,14 +1043,75 @@ def __init__( "name": "Object" } +class ObjectIdentifier(serde.Model): + """The identifier of an object to delete.""" + + _attribute_map = { + "key": {"tag": "xml", "rename": "Key", "required": True}, + "version_id": {"tag": "xml", "rename": "VersionId"}, + } + + _xml_map = { + "name": "Object" + } + + def __init__( + self, + key: Optional[str] = None, + version_id: Optional[str] = None, + **kwargs: Any + ) -> None: + """ + Args: + key (str, required): The name of the object. + version_id (str, optional): The version ID of the object. + """ + super().__init__(**kwargs) + self.key = key + self.version_id = version_id + + +class Delete(serde.Model): + """The container for the objects to delete.""" + + _attribute_map = { + "objects": {"tag": "xml", "rename": "Object", "type": "[ObjectIdentifier]"}, + "quiet": {"tag": "xml", "rename": "Quiet", "type": "bool"}, + } + + _xml_map = { + "name": "Delete" + } + + _dependency_map = { + "ObjectIdentifier": {"new": lambda: ObjectIdentifier()}, + } + + def __init__( + self, + objects: Optional[List[ObjectIdentifier]] = None, + quiet: Optional[bool] = None, + **kwargs: Any + ) -> None: + """ + Args: + objects (List[ObjectIdentifier], optional): The list of objects to delete. + quiet (bool, optional): Specifies whether to enable the Quiet return mode. + """ + super().__init__(**kwargs) + self.objects = objects + self.quiet = quiet + + class DeleteMultipleObjectsRequest(serde.RequestModel): """The request for the DeleteMultipleObjects operation.""" _attribute_map = { "bucket": {"tag": "input", "position": "host", "required": True}, "encoding_type": {"tag": "input", "position": "query", "rename": "encoding-type"}, - "objects": {"tag": "input", "position": "nop", "required": True}, + "objects": {"tag": "input", "position": "nop"}, "quiet": {"tag": "input", "position": "nop"}, + "delete": {"tag": "input", "position": "body", "rename": "nop"}, "request_payer": {"tag": "input", "position": "header", "rename": "x-oss-request-payer"}, } @@ -1060,6 +1121,7 @@ def __init__( encoding_type: Optional[str] = None, objects: Optional[List[DeleteObject]] = None, quiet: Optional[bool] = None, + delete: Optional[Delete] = None, request_payer: Optional[str] = None, **kwargs: Any ) -> None: @@ -1070,6 +1132,7 @@ def __init__( objects ([DeleteObject], optional): The container that stores information about you want to delete objects. quiet (bool, optional): Specifies whether to enable the Quiet return mode. The DeleteMultipleObjects operation provides the following return modes: Valid value: true,false + delete (Delete, optional): The container that stores information about you want to delete objects. request_payer (str, optional): To indicate that the requester is aware that the request and data download will incur costs. """ super().__init__(**kwargs) @@ -1077,6 +1140,7 @@ def __init__( self.encoding_type = encoding_type self.objects = objects self.quiet = quiet + self.delete = delete self.request_payer = request_payer diff --git a/alibabacloud_oss_v2/serde_utils.py b/alibabacloud_oss_v2/serde_utils.py index cd65b4a..3aa367b 100644 --- a/alibabacloud_oss_v2/serde_utils.py +++ b/alibabacloud_oss_v2/serde_utils.py @@ -235,20 +235,48 @@ def serialize_delete_objects(request: serde.Model, op_input: OperationInput) -> if not isinstance(request, DeleteMultipleObjectsRequest): raise exceptions.SerializationError(error=f'Unsupport type {type(request)}') + # Check if both old and new parameters are set or neither is set + has_old_params = request.objects is not None or request.quiet is not None + has_new_params = request.delete is not None + + if (has_old_params and has_new_params) or (not has_old_params and not has_new_params): + raise exceptions.SerializationError( + error='Either old parameters (objects, quiet) or new parameter (delete) must be set, but not both' + ) + xml = '' - if request.quiet is not None: - xml += f'{"true" if request.quiet else "false"}' - - if isinstance(request.objects, List): - for _, o in enumerate(request.objects): - xml += '' - key = utils.safety_str(o.key) - if len(key) > 0: - xml += f'{utils.escape_xml_value(key)}' - vid = utils.safety_str(o.version_id) - if len(vid) > 0: - xml += f'{vid}' - xml += '' + + # Handle new parameter (delete) + if has_new_params: + if request.delete.quiet is not None: + xml += f'{"true" if request.delete.quiet else "false"}' + + if isinstance(request.delete.objects, List): + for _, o in enumerate(request.delete.objects): + xml += '' + key = utils.safety_str(o.key) + if len(key) > 0: + xml += f'{utils.escape_xml_value(key)}' + vid = utils.safety_str(o.version_id) + if len(vid) > 0: + xml += f'{vid}' + xml += '' + + # Handle old parameters (objects, quiet) + elif has_old_params: + if request.quiet is not None: + xml += f'{"true" if request.quiet else "false"}' + + if isinstance(request.objects, List): + for _, o in enumerate(request.objects): + xml += '' + key = utils.safety_str(o.key) + if len(key) > 0: + xml += f'{utils.escape_xml_value(key)}' + vid = utils.safety_str(o.version_id) + if len(vid) > 0: + xml += f'{vid}' + xml += '' xml += '' diff --git a/sample/delete_multiple_objects.py b/sample/delete_multiple_objects.py index 28c5c16..d873d84 100644 --- a/sample/delete_multiple_objects.py +++ b/sample/delete_multiple_objects.py @@ -42,6 +42,28 @@ def main(): f' encoding type: {result.encoding_type},' ) + # New mode using Delete parameter + # delete_request = oss.Delete( + # objects=[ + # oss.ObjectIdentifier(key=args.key) + # ], + # quiet=False + # ) + # + # result = client.delete_multiple_objects(oss.DeleteMultipleObjectsRequest( + # bucket=args.bucket, + # delete=delete_request, + # )) + # + # print(f'status code: {result.status_code},' + # f' request id: {result.request_id},' + # f' key: {result.deleted_objects[0].key},' + # f' version id: {result.deleted_objects[0].version_id},' + # f' delete marker: {result.deleted_objects[0].delete_marker},' + # f' delete marker version id: {result.deleted_objects[0].delete_marker_version_id},' + # f' encoding type: {result.encoding_type},' + # ) + if __name__ == "__main__": main() diff --git a/tests/integration/test_client.py b/tests/integration/test_client.py index f513e4a..2405bf5 100644 --- a/tests/integration/test_client.py +++ b/tests/integration/test_client.py @@ -1022,6 +1022,82 @@ def test_delete_multiple_objects(self): serr = cast(oss.exceptions.ServiceError, serr) self.assertIn('NoSuchKey', serr.code) + def test_delete_multiple_objects_with_delete_parameter(self): + # Test the new Delete parameter mode + length = 1234 + data = random_str(length) + key1 = OBJECTNAME_PREFIX + random_str(16) + key2 = OBJECTNAME_PREFIX + random_str(16) + + # Put objects to be deleted + result1 = self.client.put_object(oss.PutObjectRequest( + bucket=self.bucket_name, + key=key1, + body=data, + )) + self.assertIsNotNone(result1) + self.assertEqual(200, result1.status_code) + + result2 = self.client.put_object(oss.PutObjectRequest( + bucket=self.bucket_name, + key=key2, + body=data, + )) + self.assertIsNotNone(result2) + self.assertEqual(200, result2.status_code) + + # Delete multiple objects using the new Delete parameter + delete_request = oss.Delete( + objects=[ + oss.ObjectIdentifier(key=key1), + oss.ObjectIdentifier(key=key2) + ], + quiet=False + ) + + result = self.client.delete_multiple_objects(oss.DeleteMultipleObjectsRequest( + bucket=self.bucket_name, + delete=delete_request, + )) + + self.assertIsInstance(result, oss.DeleteMultipleObjectsResult) + self.assertEqual(200, result.status_code) + self.assertIsNotNone(result.headers.get('x-oss-request-id')) + self.assertEqual(2, len(result.deleted_objects)) + + deleted_keys = [obj.key for obj in result.deleted_objects] + self.assertIn(key1, deleted_keys) + self.assertIn(key2, deleted_keys) + + # Verify objects are deleted + try: + self.client.head_object(oss.HeadObjectRequest( + bucket=self.bucket_name, + key=key1, + )) + self.fail("Should have raised an exception") + except Exception as err: + self.assertIsInstance(err, oss.exceptions.OperationError) + err = cast(oss.exceptions.OperationError, err) + serr = err.unwrap() + self.assertIsInstance(serr, oss.exceptions.ServiceError) + serr = cast(oss.exceptions.ServiceError, serr) + self.assertIn('NoSuchKey', serr.code) + + try: + self.client.head_object(oss.HeadObjectRequest( + bucket=self.bucket_name, + key=key2, + )) + self.fail("Should have raised an exception") + except Exception as err: + self.assertIsInstance(err, oss.exceptions.OperationError) + err = cast(oss.exceptions.OperationError, err) + serr = err.unwrap() + self.assertIsInstance(serr, oss.exceptions.ServiceError) + serr = cast(oss.exceptions.ServiceError, serr) + self.assertIn('NoSuchKey', serr.code) + def test_restore_object(self): length = 123 data = random_str(length) diff --git a/tests/integration/test_object_basic_async.py b/tests/integration/test_object_basic_async.py index 2257075..46ea9d0 100644 --- a/tests/integration/test_object_basic_async.py +++ b/tests/integration/test_object_basic_async.py @@ -356,6 +356,82 @@ async def test_delete_multiple_objects(self): serr = cast(oss.exceptions.ServiceError, serr) self.assertIn('NoSuchKey', serr.code) + async def test_delete_multiple_objects_with_delete_parameter(self): + # Test the new Delete parameter mode + length = 1234 + data = random_str(length) + key1 = OBJECTNAME_PREFIX + random_str(16) + key2 = OBJECTNAME_PREFIX + random_str(16) + + # Put objects to be deleted + result1 = await self.async_client.put_object(oss.PutObjectRequest( + bucket=self.bucket_name, + key=key1, + body=data, + )) + self.assertIsNotNone(result1) + self.assertEqual(200, result1.status_code) + + result2 = await self.async_client.put_object(oss.PutObjectRequest( + bucket=self.bucket_name, + key=key2, + body=data, + )) + self.assertIsNotNone(result2) + self.assertEqual(200, result2.status_code) + + # Delete multiple objects using the new Delete parameter + delete_request = oss.Delete( + objects=[ + oss.ObjectIdentifier(key=key1), + oss.ObjectIdentifier(key=key2) + ], + quiet=False + ) + + result = await self.async_client.delete_multiple_objects(oss.DeleteMultipleObjectsRequest( + bucket=self.bucket_name, + delete=delete_request, + )) + + self.assertIsInstance(result, oss.DeleteMultipleObjectsResult) + self.assertEqual(200, result.status_code) + self.assertIsNotNone(result.headers.get('x-oss-request-id')) + self.assertEqual(2, len(result.deleted_objects)) + + deleted_keys = [obj.key for obj in result.deleted_objects] + self.assertIn(key1, deleted_keys) + self.assertIn(key2, deleted_keys) + + # Verify objects are deleted + try: + await self.async_client.head_object(oss.HeadObjectRequest( + bucket=self.bucket_name, + key=key1, + )) + self.fail("Should have raised an exception") + except Exception as err: + self.assertIsInstance(err, oss.exceptions.OperationError) + err = cast(oss.exceptions.OperationError, err) + serr = err.unwrap() + self.assertIsInstance(serr, oss.exceptions.ServiceError) + serr = cast(oss.exceptions.ServiceError, serr) + self.assertIn('NoSuchKey', serr.code) + + try: + await self.async_client.head_object(oss.HeadObjectRequest( + bucket=self.bucket_name, + key=key2, + )) + self.fail("Should have raised an exception") + except Exception as err: + self.assertIsInstance(err, oss.exceptions.OperationError) + err = cast(oss.exceptions.OperationError, err) + serr = err.unwrap() + self.assertIsInstance(serr, oss.exceptions.ServiceError) + serr = cast(oss.exceptions.ServiceError, serr) + self.assertIn('NoSuchKey', serr.code) + async def test_restore_object(self): length = 123 data = random_str(length) diff --git a/tests/unit/models/test_object_basic.py b/tests/unit/models/test_object_basic.py index 8c05cb9..08f659a 100644 --- a/tests/unit/models/test_object_basic.py +++ b/tests/unit/models/test_object_basic.py @@ -2,7 +2,7 @@ import datetime import unittest import xml.etree.ElementTree as ET -from alibabacloud_oss_v2 import serde +from alibabacloud_oss_v2 import serde, serde_utils from alibabacloud_oss_v2.models import object_basic as model from alibabacloud_oss_v2.types import OperationInput, OperationOutput, CaseInsensitiveDict from .. import MockHttpResponse @@ -1413,6 +1413,209 @@ def test_constructor_request(self): self.assertDictEqual({'parm1': 'value1'}, request.parameters) self.assertEqual('hello world', request.payload) + def test_delete_multiple_objects_request_with_delete(self): + # Test constructor with Delete parameter + request = model.DeleteMultipleObjectsRequest( + bucket='bucket_name', + delete=model.Delete( + quiet=True, + objects=[ + model.ObjectIdentifier( + key='key1', + version_id='version1' + ), + model.ObjectIdentifier( + key='key2', + version_id='version2' + ) + ] + ) + ) + self.assertIsNotNone(request.bucket) + self.assertIsNotNone(request.delete) + self.assertIsNone(request.encoding_type) + self.assertIsNone(request.objects) + self.assertIsNone(request.quiet) + self.assertIsNone(request.request_payer) + self.assertEqual('bucket_name', request.bucket) + self.assertTrue(request.delete.quiet) + self.assertEqual(2, len(request.delete.objects)) + self.assertEqual('key1', request.delete.objects[0].key) + self.assertEqual('version1', request.delete.objects[0].version_id) + self.assertEqual('key2', request.delete.objects[1].key) + self.assertEqual('version2', request.delete.objects[1].version_id) + self.assertIsInstance(request, serde.RequestModel) + + # Test constructor with both old and new parameters - should work for construction + request = model.DeleteMultipleObjectsRequest( + bucket='bucket_name', + objects=[model.DeleteObject(key='old_key')], + quiet=False, + delete=model.Delete( + quiet=True, + objects=[ + model.ObjectIdentifier(key='new_key') + ] + ), + encoding_type='url', + request_payer='requester' + ) + self.assertEqual('bucket_name', request.bucket) + # New parameter should be preserved + self.assertIsNotNone(request.delete) + self.assertTrue(request.delete.quiet) + self.assertEqual(1, len(request.delete.objects)) + self.assertEqual('new_key', request.delete.objects[0].key) + # Old parameters should also be preserved + self.assertIsNotNone(request.objects) + self.assertEqual(1, len(request.objects)) + self.assertEqual('old_key', request.objects[0].key) + self.assertFalse(request.quiet) + self.assertEqual('url', request.encoding_type) + self.assertEqual('requester', request.request_payer) + + def test_serialize_delete_multiple_objects_request_with_delete(self): + # Test serialization with new Delete parameter + request_new = model.DeleteMultipleObjectsRequest( + bucket='bucket_name', + delete=model.Delete( + quiet=True, + objects=[ + model.ObjectIdentifier( + key='key1', + version_id='version1' + ), + model.ObjectIdentifier( + key='key2' + ) + ] + ), + request_payer='requester' + ) + + op_input_new = serde.serialize_input( + request_new, + OperationInput( + op_name='DeleteMultipleObjects', + method='POST', + bucket=request_new.bucket, + ), + custom_serializer=[ + serde_utils.serialize_delete_objects, + serde_utils.add_content_md5, + ], + ) + self.assertEqual('DeleteMultipleObjects', op_input_new.op_name) + self.assertEqual('POST', op_input_new.method) + self.assertEqual('bucket_name', op_input_new.bucket) + self.assertEqual('requester', op_input_new.headers.get('x-oss-request-payer')) + + # Check if the body contains the correct XML for new parameter + import xml.etree.ElementTree as ET + root_new = ET.fromstring(op_input_new.body) + self.assertEqual('Delete', root_new.tag) + self.assertEqual('true', root_new.findtext('Quiet')) + objects_new = root_new.findall('Object') + self.assertEqual(2, len(objects_new)) + self.assertEqual('key1', objects_new[0].findtext('Key')) + self.assertEqual('version1', objects_new[0].findtext('VersionId')) + self.assertEqual('key2', objects_new[1].findtext('Key')) + self.assertIsNone(objects_new[1].find('VersionId')) + + # Test serialization with old parameters + request_old = model.DeleteMultipleObjectsRequest( + bucket='bucket_name', + objects=[ + model.DeleteObject( + key='key1', + version_id='version1' + ), + model.DeleteObject( + key='key2' + ) + ], + quiet=True, + request_payer='requester' + ) + + op_input_old = serde.serialize_input( + request_old, + OperationInput( + op_name='DeleteMultipleObjects', + method='POST', + bucket=request_old.bucket, + ), + custom_serializer=[ + serde_utils.serialize_delete_objects, + serde_utils.add_content_md5, + ], + ) + self.assertEqual('DeleteMultipleObjects', op_input_old.op_name) + self.assertEqual('POST', op_input_old.method) + self.assertEqual('bucket_name', op_input_old.bucket) + self.assertEqual('requester', op_input_old.headers.get('x-oss-request-payer')) + + # Check if the body contains the correct XML for old parameters + root_old = ET.fromstring(op_input_old.body) + self.assertEqual('Delete', root_old.tag) + self.assertEqual('true', root_old.findtext('Quiet')) + objects_old = root_old.findall('Object') + self.assertEqual(2, len(objects_old)) + self.assertEqual('key1', objects_old[0].findtext('Key')) + self.assertEqual('version1', objects_old[0].findtext('VersionId')) + self.assertEqual('key2', objects_old[1].findtext('Key')) + self.assertIsNone(objects_old[1].find('VersionId')) + + # Compare the XML generated by new and old parameters - they should be identical + self.assertEqual(op_input_new.body, op_input_old.body) + + def test_serialize_delete_multiple_objects_request_error_conditions(self): + # Test serialization error when neither old nor new parameters are set + request = model.DeleteMultipleObjectsRequest( + bucket='bucket_name', + ) + + with self.assertRaises(Exception) as context: + serde.serialize_input( + request, + OperationInput( + op_name='DeleteMultipleObjects', + method='POST', + bucket=request.bucket, + ), + custom_serializer=[ + serde_utils.serialize_delete_objects, + serde_utils.add_content_md5, + ], + ) + self.assertIn('Either old parameters', str(context.exception)) + + # Test serialization error when both old and new parameters are set + request = model.DeleteMultipleObjectsRequest( + bucket='bucket_name', + objects=[model.DeleteObject(key='old_key')], + delete=model.Delete( + quiet=True, + objects=[model.ObjectIdentifier(key='new_key')] + ) + ) + + with self.assertRaises(Exception) as context: + serde.serialize_input( + request, + OperationInput( + op_name='DeleteMultipleObjects', + method='POST', + bucket=request.bucket, + ), + custom_serializer=[ + serde_utils.serialize_delete_objects, + serde_utils.add_content_md5, + ], + ) + self.assertIn('Either old parameters', str(context.exception)) + + def test_serialize_request(self): request = model.DeleteMultipleObjectsRequest( bucket='bucket_name', From 1ce07f18b4515c5847fb565a129d2d6a32279cec Mon Sep 17 00:00:00 2001 From: zhuxiaolong37 Date: Wed, 5 Nov 2025 17:29:20 +0800 Subject: [PATCH 2/3] Change the position of the new parameter to the end --- alibabacloud_oss_v2/models/object_basic.py | 8 ++++---- tests/unit/models/test_object_basic.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/alibabacloud_oss_v2/models/object_basic.py b/alibabacloud_oss_v2/models/object_basic.py index 02eee6e..5cf6ed5 100644 --- a/alibabacloud_oss_v2/models/object_basic.py +++ b/alibabacloud_oss_v2/models/object_basic.py @@ -1111,8 +1111,8 @@ class DeleteMultipleObjectsRequest(serde.RequestModel): "encoding_type": {"tag": "input", "position": "query", "rename": "encoding-type"}, "objects": {"tag": "input", "position": "nop"}, "quiet": {"tag": "input", "position": "nop"}, - "delete": {"tag": "input", "position": "body", "rename": "nop"}, "request_payer": {"tag": "input", "position": "header", "rename": "x-oss-request-payer"}, + "delete": {"tag": "input", "position": "body", "rename": "nop"}, } def __init__( @@ -1121,8 +1121,8 @@ def __init__( encoding_type: Optional[str] = None, objects: Optional[List[DeleteObject]] = None, quiet: Optional[bool] = None, - delete: Optional[Delete] = None, request_payer: Optional[str] = None, + delete: Optional[Delete] = None, **kwargs: Any ) -> None: """ @@ -1132,16 +1132,16 @@ def __init__( objects ([DeleteObject], optional): The container that stores information about you want to delete objects. quiet (bool, optional): Specifies whether to enable the Quiet return mode. The DeleteMultipleObjects operation provides the following return modes: Valid value: true,false - delete (Delete, optional): The container that stores information about you want to delete objects. request_payer (str, optional): To indicate that the requester is aware that the request and data download will incur costs. + delete (Delete, optional): The container that stores information about you want to delete objects. """ super().__init__(**kwargs) self.bucket = bucket self.encoding_type = encoding_type self.objects = objects self.quiet = quiet - self.delete = delete self.request_payer = request_payer + self.delete = delete class DeletedInfo(serde.Model): diff --git a/tests/unit/models/test_object_basic.py b/tests/unit/models/test_object_basic.py index 08f659a..3f26ae1 100644 --- a/tests/unit/models/test_object_basic.py +++ b/tests/unit/models/test_object_basic.py @@ -1593,11 +1593,11 @@ def test_serialize_delete_multiple_objects_request_error_conditions(self): # Test serialization error when both old and new parameters are set request = model.DeleteMultipleObjectsRequest( bucket='bucket_name', - objects=[model.DeleteObject(key='old_key')], delete=model.Delete( quiet=True, objects=[model.ObjectIdentifier(key='new_key')] - ) + ), + objects=[model.DeleteObject(key='old_key')], ) with self.assertRaises(Exception) as context: From c974b090cbe73359140e1be3a7587eb73d391913 Mon Sep 17 00:00:00 2001 From: zhuxiaolong37 Date: Thu, 6 Nov 2025 15:49:52 +0800 Subject: [PATCH 3/3] Update the has_old_params detection logic, and add deprecation notices in the comments for the objects and quiet fields. --- alibabacloud_oss_v2/models/object_basic.py | 2 + alibabacloud_oss_v2/serde_utils.py | 2 +- sample/delete_multiple_objects.py | 45 ++++++++-------------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/alibabacloud_oss_v2/models/object_basic.py b/alibabacloud_oss_v2/models/object_basic.py index 5cf6ed5..4debb0d 100644 --- a/alibabacloud_oss_v2/models/object_basic.py +++ b/alibabacloud_oss_v2/models/object_basic.py @@ -1130,8 +1130,10 @@ def __init__( bucket (str, required): The name of the bucket. encoding_type (str, optional): The encoding type of the object names in the response. Valid value: url objects ([DeleteObject], optional): The container that stores information about you want to delete objects. + This parameter is deprecated. Use 'delete' parameter instead. quiet (bool, optional): Specifies whether to enable the Quiet return mode. The DeleteMultipleObjects operation provides the following return modes: Valid value: true,false + This parameter is deprecated. Use 'delete' parameter instead. request_payer (str, optional): To indicate that the requester is aware that the request and data download will incur costs. delete (Delete, optional): The container that stores information about you want to delete objects. """ diff --git a/alibabacloud_oss_v2/serde_utils.py b/alibabacloud_oss_v2/serde_utils.py index 3aa367b..c221385 100644 --- a/alibabacloud_oss_v2/serde_utils.py +++ b/alibabacloud_oss_v2/serde_utils.py @@ -236,7 +236,7 @@ def serialize_delete_objects(request: serde.Model, op_input: OperationInput) -> raise exceptions.SerializationError(error=f'Unsupport type {type(request)}') # Check if both old and new parameters are set or neither is set - has_old_params = request.objects is not None or request.quiet is not None + has_old_params = request.objects is not None has_new_params = request.delete is not None if (has_old_params and has_new_params) or (not has_old_params and not has_new_params): diff --git a/sample/delete_multiple_objects.py b/sample/delete_multiple_objects.py index d873d84..ab0f238 100644 --- a/sample/delete_multiple_objects.py +++ b/sample/delete_multiple_objects.py @@ -24,15 +24,27 @@ def main(): client = oss.Client(cfg) - # If deleting multiple items, please follow the following format + # If deleting multiple items, please follow the following format (deprecated) # objects = [oss.DeleteObject(key=args.key), oss.DeleteObject(key=args.key2)], + # result = client.delete_multiple_objects(oss.DeleteMultipleObjectsRequest( + # bucket=args.bucket, + # encoding_type='url', + # objects=[oss.DeleteObject(key=args.key)], + # )) + # New mode using Delete parameter + delete_request = oss.Delete( + objects=[ + oss.ObjectIdentifier(key=args.key) + ], + quiet=False + ) + result = client.delete_multiple_objects(oss.DeleteMultipleObjectsRequest( bucket=args.bucket, - encoding_type='url', - objects=[oss.DeleteObject(key=args.key)], + delete=delete_request, )) - + print(f'status code: {result.status_code},' f' request id: {result.request_id},' f' key: {result.deleted_objects[0].key},' @@ -42,29 +54,6 @@ def main(): f' encoding type: {result.encoding_type},' ) - # New mode using Delete parameter - # delete_request = oss.Delete( - # objects=[ - # oss.ObjectIdentifier(key=args.key) - # ], - # quiet=False - # ) - # - # result = client.delete_multiple_objects(oss.DeleteMultipleObjectsRequest( - # bucket=args.bucket, - # delete=delete_request, - # )) - # - # print(f'status code: {result.status_code},' - # f' request id: {result.request_id},' - # f' key: {result.deleted_objects[0].key},' - # f' version id: {result.deleted_objects[0].version_id},' - # f' delete marker: {result.deleted_objects[0].delete_marker},' - # f' delete marker version id: {result.deleted_objects[0].delete_marker_version_id},' - # f' encoding type: {result.encoding_type},' - # ) - if __name__ == "__main__": - main() - + main() \ No newline at end of file