Add questionnaire reset functionality - #1532
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds “questionnaire reset” behavior by tracking an exercise content-version hash (from mooc-grader) and the submission language, and reloading a fresh exercise page when the latest submission no longer matches the current exercise version or UI language.
Changes:
- Persist an
exercise_versionhash from the exercise service intoExercisePageandExerciseCache. - Stamp the current
exercise_versioninto new submissions’ metadata for later compatibility checks. - In the exercise view, compare the latest submission’s stored version/language against the current ones and reset (reload blank exercise) on mismatch.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| exercise/views.py | Adds reset logic when current exercise version/language differs from the latest submission’s metadata. |
| exercise/submission_models.py | Stamps exercise_version into submission metadata at submission creation time. |
| exercise/protocol/exercise_page.py | Introduces exercise_version field on ExercisePage. |
| exercise/protocol/aplus.py | Parses x-aplus-exercise-version from the remote page meta into ExercisePage. |
| exercise/cache/exercise.py | Stores exercise_version in the cached exercise page data and refreshes legacy cache entries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Sorry for the confusion :) tried to make things look nice on my repo but ended up breaking things |
f8f12ef to
8c19aa6
Compare
|
Looks reasonable. What's the idea behind VERSION_MAX_AGE, though? If there's been no changes, why would we need to reload? |
|
I believe that was added by AI as a fallback in case the exercise somehow gets modified without triggering A+ exercise cache invalidation: "VERSION_MAX_AGE prevents trusting that raw version hash forever. After 15 minutes, it returns “no cached version,” causing the view to load the exercise page and try to obtain a current hash.
But in our case edits that save the A+ What do you think @murhum1 ? |
Description
What?
Make questionnaire exercises reset and not show previous answer when they have been edited or when the course language is changed
Why?
This is done so that the correct version of a questionnaire is always shown to students
How?
A-plus checks an exercise version hash from mooc-grader (separate PR on mooc-grader) and compares it to the latest submission's hash. The page's language is compared as well to the submission's, and if either mismatch, the form is reset.
Fixes #494
Testing
Remember to add or update unit tests for new features and changes.
What type of test did you run?
I tested that the reset functionality works in the UI by editing aplus-manual and reloading a-plus while keeping old submission data cached. I also tested the language change.
Did you test the changes in
Think of what is affected by these changes and could become broken
Translation
Programming style
Have you updated the README or other relevant documentation?
Is it Done?
Clean up your git commit history before submitting the pull request!