botocore
botocore copied to clipboard
CommonPrefixes not parsed correctly if it contains multiple Prefix tags
<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>]}]}
Hi @smoofra,
Have you seen this behavior in the wild with an actual request?
@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.
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.
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.