azure-functions-python-worker icon indicating copy to clipboard operation
azure-functions-python-worker copied to clipboard

[BUG] FileStorage.save() silently fails when called multiple times

Open ssmid opened this issue 1 year ago • 2 comments

Problem: When FileStorage.save() is called a second time, it saves 0 bytes into a file because its underlying stream is used up.

Expected: Raises an error when called more than once.

Solution: Set self.stream to None after it has been used and check if self.stream is None already.

https://github.com/Azure/azure-functions-python-library/blob/fc78a0691d6da4b9860346a79f9f30fb87ba135f/azure/functions/_thirdparty/werkzeug/datastructures.py#L2796

ssmid avatar Jun 17 '24 11:06 ssmid

Thanks for informing please share the all repro steps code snippet if possible.Thanks

bhagyshricompany avatar Jun 28 '24 11:06 bhagyshricompany

Funny policy, because this issue had been inactive for 11 days prior. Also, I don't think this issue needs additional info.

ssmid avatar Jul 02 '24 14:07 ssmid

Hi @ssmid, thanks for reporting this issue.

Could you explain your use case / scenario a little more please? Or more specifically, why do you want an error thrown in this scenario and why is FileStorage.save() being called multiple times?

I'm assuming what might be happening is FileStorage.save() is being called multiple times, and since the stream has been used up the file is overwritten with 0 bytes. Is that the case here?

The copyfileobj method itself doesn't throw any errors if the stream is used up, so this isn't an unsupported scenario. Throwing a new error or changing the functionality (to, say, not writing anything if the stream is empty) could be a large change, and we want to maintain as much backwards compatibility as possible. If the issue is with not knowing if the FileStorage.save() method has executed already, maybe a better solution could be returning if the method has been called already or not.

hallvictoria avatar Jul 10 '24 21:07 hallvictoria

I am speechless.

ssmid avatar Jul 10 '24 22:07 ssmid