botocore icon indicating copy to clipboard operation
botocore copied to clipboard

CommonPrefixes not parsed correctly if it contains multiple Prefix tags

Open smoofra opened this issue 4 years ago • 4 comments

<CommonPrefixes> is not parsed correctly if it contains multiple <Prefix> tags.

S3 itself does not behave this way but S3Mock does (https://github.com/adobe/S3Mock/issues/215)

This may be an incorrect response but if it is botocore should raise an error not just return raw xml Element objects

tested with botocore 1.20.24

import botocore.session
session = botocore.session.get_session()
operation_model = session.get_service_model("s3").operation_model('ListMultipartUploads')
protocol = operation_model.service_model.protocol
parser_cls = botocore.parsers.PROTOCOL_PARSERS[protocol]
parser = parser_cls(timestamp_parser=lambda x: x)
parser
body = """
<?xml version="1.0" encoding="UTF-8"?>
<ListMultipartUploadsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <Bucket>botocoretest1374528673-218</Bucket>
  <NextUploadIdMarker></NextUploadIdMarker>
  <Delimiter>/</Delimiter>
  <Prefix>foo</Prefix>
  <MaxUploads>1000</MaxUploads>
  <IsTruncated>false</IsTruncated>
  <CommonPrefixes>
	<Prefix>foo/</Prefix>
	<Prefix>foobar/</Prefix>
</CommonPrefixes>
</ListMultipartUploadsResult>
""".strip()
parsed = parser.parse({'body':body, 'headers':{}, 'status_code':200}, operation_model.output_shape)
parsed
{'ResponseMetadata': {'HTTPStatusCode': 200, 'HTTPHeaders': {}},
 'Bucket': 'botocoretest1374528673-218',
 'Prefix': 'foo',
 'Delimiter': '/',
 'NextUploadIdMarker': '',
 'MaxUploads': 1000,
 'IsTruncated': False,
 'CommonPrefixes': [{'Prefix': [<Element '{http://s3.amazonaws.com/doc/2006-03-01/}Prefix' at 0x1098830e0>,
    <Element '{http://s3.amazonaws.com/doc/2006-03-01/}Prefix' at 0x109883130>]}]}

smoofra avatar Mar 10 '21 02:03 smoofra

Hi @smoofra,

Have you seen this behavior in the wild with an actual request?

kdaily avatar Mar 23 '21 22:03 kdaily

@kdaily

Have you seen this behavior in the wild with an actual request?

Yes, I encountered it when I was writing some unit tests for my application using s3mock.

smoofra avatar Mar 23 '21 22:03 smoofra

Hi @smoofra,

Thanks. I meant have you seen it when running a request against an actual AWS S3 endpoint?

I can reproduce your example, but I'm not familiar enough with using delimiters to know immediately if the syntax is not correct. I also tried it with a real response for a ListObjectsV2 request where there are multiple prefixes, and it parsed it as expected.

kdaily avatar Jun 03 '21 16:06 kdaily

um, sorry I didn't respond to that question @kdaily. No actual AWS endpoints don't generate responses like that one as far as I know.

smoofra avatar Mar 17 '23 00:03 smoofra