Safeguard lab answer saving against blank overwrites (Firefox)#285
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds defense-in-depth so a blank/partial form submission can never wipe a user's saved lab answers, and adds extra logging around the save path.
Why
Firefox users reported their lab answers being replaced by a dict of all answer names with empty-string values. Root cause: Firefox's built-in form-state restoration re-blanks the guide inputs after page load and dispatches synthetic
change/inputevents. Those events hit the debounced auto-save, which serialized the now-blank form and POSTed{q1:"", q2:"", ...}, and the server overwrote the good answers.Changes
Client (
apps/templates/pages/lab_instance_view.html):saveAnswers()bails out before POSTing when every field is blank, so an all-empty form can never overwrite stored answers.autocomplete="off"on all#lab-guideinputs so Firefox stops restoring/re-blanking them after load (removing the source of the spurious change events).answersLoadedguard that suppresses auto-save until the initial load settles.Server (
apps/api/routes.py):save_lab_answersnow merges per-key into the stored answers instead of replacing them: an empty/Noneincoming value is skipped when a stored answer already exists, so even a partially blank payload cannot erase individual saved answers.Also adds extra logging around the save-answers flow to aid future diagnosis.
Reviewer notes