#36191 closed Bug (fixed)
FileSystemStorage with allow_overwrite=True does not truncate previous file
Description ¶
The new allow_overwrite parameter of FileSystemStorage class allows to overwrite an existing file. However, the previous file is not truncated. So, if the previous file was bigger than the new, the file gets corrupted.
It is possible to workaround with :
storage.OS_OPEN_FLAGS = storage.OS_OPEN_FLAGS & ~os.O_EXCL | os.O_TRUNC
Change History (8)
comment:1 by , 2 weeks ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
Version 0, edited 2 weeks ago by (next)
comment:2 by , 2 weeks ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:3 by , 2 weeks ago
Has patch: | set |
---|
comment:4 by , 2 weeks ago
Jacob, thanks for your confirmation of the bug, and confirmation of the fix I had in mind.
I pushed a PR, including your idea to assert the length of both contents in the test.
It's my first contribution to Django. I read the docs. I hope I did it right.
comment:5 by , 2 weeks ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
Thanks for the report, reproduced by adjusting this existing test case:
TabularUnified tests/file_storage/tests.py
Test passes with the suggested patch:
Would you like to submit a PR?