shcherbin commented on a change in pull request #7375: [AIRFLOW-5231] Fix
S3Hook.delete_objects method
URL: https://github.com/apache/airflow/pull/7375#discussion_r376953306
##########
File path: airflow/providers/amazon/aws/hooks/s3.py
##########
@@ -610,7 +611,18 @@ def delete_objects(self, bucket, keys):
if isinstance(keys, str):
keys = [keys]
- delete_dict = {"Objects": [{"Key": k} for k in keys]}
- response = self.get_conn().delete_objects(Bucket=bucket,
Delete=delete_dict)
-
- return response
+ s3 = self.get_conn()
+
+ # We can only send a maximum of 1000 keys per request.
+ # For details see:
+ #
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.delete_objects
+ for chunk in chunks(keys, chunk_size=1000):
+ response = s3.delete_objects(
+ Bucket=bucket,
+ Delete={"Objects": [{"Key": k} for k in chunk]}
+ )
+ deleted_keys = [x['Key'] for x in response.get("Deleted", [])]
+ self.log.info("Deleted: %s", deleted_keys)
+ if "Errors" in response:
+ errors_keys = [x['Key'] for x in response.get("Errors", [])]
+ raise AirflowException("Errors when deleting:
{}".format(errors_keys))
Review comment:
Done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services