harvard-lil / h2o

H2O is a web app for creating and reading open educational resources, primarily in the legal field
https://opencasebook.org
GNU Affero General Public License v3.0
35 stars 30 forks source link

Prevent duplicative merge attempts. #2036

Closed rebeccacremona closed 7 months ago

rebeccacremona commented 7 months ago

If you attempt to "publish" the same draft multiple times and make your requests quickly enough, multiple attempts may pass this test and proceed through the merging code.

That is never desirable.

And I have not yet definitively proved, but am quite convinced that this occasionally completely corrupts the casebook involved.

This PR uses select_for_update to ensure that only one publication attempt is ever in progress at once.

The user experience could still use some polishing: right now, on prod, if something goes wrong with the "publish" modal (for instance, you open two tabs with a draft, and click publish in one, wait a few seconds, and then click publish in the other), the modal just stays open. Your request gets a 400... but unless the dev tools are open, you don't see any notification.

I tried to fix that in this PR too, so that I could add an error message for THAT situation AND for the situation this PR fixes. But I couldn't figure it out...

But, I think this is worth it even without that: a weirdly not-closing modal is better than a potentially corrupted book!

codecov-commenter commented 7 months ago

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (64981a3) 76.48% compared to head (6940e62) 76.55%. Report is 1 commits behind head on develop.

Files Patch % Lines
web/main/models.py 87.50% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #2036 +/- ## =========================================== + Coverage 76.48% 76.55% +0.06% =========================================== Files 64 64 Lines 7071 7092 +21 =========================================== + Hits 5408 5429 +21 Misses 1663 1663 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

sentry-io[bot] commented 7 months ago

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

Did you find this useful? React with a 👍 or 👎