Azure / azure-storage-python

Microsoft Azure Storage Library for Python
https://azure-storage.readthedocs.io
MIT License
338 stars 240 forks source link

set_blob_service_properties generates invalid request body when all args are None #540

Closed williexu closed 5 years ago

williexu commented 5 years ago

Which service(blob, file, queue) does this issue concern?

blob

Which version of the SDK was used? Please provide the output of pip freeze.

1.3.1

What problem was encountered?

set_blob_service_properties() throws error with all args None despite expecting no-op:

azure.common.AzureHttpError: XML specified is not syntactically valid. ErrorCode: InvalidXmlDocument
<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidXmlDocument</Code><Message>XML specified is not syntactically valid.
RequestId:ae7cb42b-301e-001d-7dbd-a3fb9d000000
Time:2019-01-03T23:40:35.2283077Z</Message><LineNumber>2</LineNumber><LinePosition>29</LinePosition><Reason>Element '' is not recognized.</Reason></Error>

Debugging shows that _convert_service_properties_to_xml() generates the following improper xml: b"<?xml version='1.0' encoding='utf-8'?>\n<StorageServiceProperties />"

Have you found a mitigation/solution?

Yes, just provide one of the args

Note: for table service, please post the issue here instead: https://github.com/Azure/azure-cosmosdb-python.

zezha-msft commented 5 years ago

Hi @williexu, thanks for reaching out!

According to the REST doc, set_blob_service_properties should be called with one or more root elements specified in the request body. Thus, I think the desired behavior in your scenario should be throwing an error saying that at least some property needs to be changed. Do you agree?

williexu commented 5 years ago

@zezha-msft yes, an error telling the user to specify at least one property would work nicely. Thanks

zezha-msft commented 5 years ago

@williexu sounds good! I've added this item to our backlog.

xiafu-msft commented 5 years ago

the bug is fixed in azure-storage-blob version 2.0.1