@@ -788,14 +788,32 @@ def upload_part(self, context: RequestContext, request: UploadPartRequest) -> Up
788
788
"The specified upload does not exist. The upload ID may be invalid, or the upload may have been aborted or completed." ,
789
789
UploadId = upload_id ,
790
790
)
791
- elif (part_number := request .get ("PartNumber" , 0 )) < 1 :
791
+ elif (part_number := request .get ("PartNumber" , 0 )) < 1 or part_number >= 10000 :
792
792
raise InvalidArgument (
793
793
"Part number must be an integer between 1 and 10000, inclusive" ,
794
794
ArgumentName = "partNumber" ,
795
795
ArgumentValue = part_number ,
796
796
)
797
797
798
- response : UploadPartOutput = call_moto (context )
798
+ part = body .read () if (body := request .get ("Body" )) else b""
799
+
800
+ # we are directly using moto backend and not calling moto because to get the response, moto calls
801
+ # key.response_dict, which in turns tries to access the tags of part, indirectly creating a BackendDict
802
+ # with an account_id set to None (because moto does not set an account_id to the FakeKey representing a Part)
803
+ key = moto_backend .upload_part (bucket_name , upload_id , part_number , part )
804
+ response = UploadPartOutput (ETag = key .etag )
805
+
806
+ if key .checksum_algorithm is not None :
807
+ response [f"Checksum{ key .checksum_algorithm .upper ()} " ] = key .checksum_value
808
+
809
+ if key .encryption is not None :
810
+ response ["ServerSideEncryption" ] = key .encryption
811
+ if key .encryption == "aws:kms" and key .kms_key_id is not None :
812
+ response ["SSEKMSKeyId" ] = key .encryption
813
+
814
+ if key .encryption == "aws:kms" and key .bucket_key_enabled is not None :
815
+ response ["BucketKeyEnabled" ] = key .bucket_key_enabled
816
+
799
817
return response
800
818
801
819
@handler ("ListMultipartUploads" , expand = False )
0 commit comments