From fe270357415e9091b3702f262e7ce52ab365e93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Far=C3=ADas=20Santana?= Date: Wed, 4 Dec 2024 16:45:04 +0100 Subject: [PATCH] fix: Upload S3 parts in sorted order --- posthog/temporal/batch_exports/s3_batch_export.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/posthog/temporal/batch_exports/s3_batch_export.py b/posthog/temporal/batch_exports/s3_batch_export.py index 62071fa866363..7201af91d2b5a 100644 --- a/posthog/temporal/batch_exports/s3_batch_export.py +++ b/posthog/temporal/batch_exports/s3_batch_export.py @@ -5,6 +5,7 @@ import datetime as dt import io import json +import operator import posixpath import typing @@ -285,12 +286,13 @@ async def complete(self) -> str: if self.is_upload_in_progress() is False: raise NoUploadInProgressError() + sorted_parts = sorted(self.parts, key=operator.itemgetter("PartNumber")) async with self.s3_client() as s3_client: response = await s3_client.complete_multipart_upload( Bucket=self.bucket_name, Key=self.key, UploadId=self.upload_id, - MultipartUpload={"Parts": self.parts}, + MultipartUpload={"Parts": sorted_parts}, ) self.upload_id = None