kobotoolbox / kobocat

Our (backend) server for providing blank forms to Collect and Enketo and for receiving and storing submissions.
BSD 2-Clause "Simplified" License
117 stars 126 forks source link

Regroup storage counter calculation in the same DB transaction #897

Closed noliveleger closed 1 year ago

noliveleger commented 1 year ago

Description

Avoid discrepancy when something goes wrong (e.g. one counter is decreased but not the other)

Notes

Use default_storage_class to get rid of the file on storage instead of letting the FileField media_file handle it. As explained in the comments of this PR, attachment.media_file.delete() could rise to a race condition on counter update.