Repository navigation
Don't show raw exception text in flash messages - #183
Merged
Merged
Conversation
Handlers flashed str(e), which for a database error carries the SQL statement, its parameters (student data during imports) and the database's host into the session cookie. Now: - a duplicate exam name is checked before inserting, and a duplicate room or exam that slips past the check (IntegrityError) is reported in plain terms - DataValidationError and GcpError messages, written for users, are still shown, prefixed with what failed - anything else is logged with its traceback under a short reference, and the flash says what failed and gives the reference Room imports also roll back after a failed commit, and no longer try to save a room that failed to build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🚀 Staging Preview Deployed! URL: https://preview-seating-pr-183-137456085712.us-west1.run.app |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #183 +/- ##
==========================================
+ Coverage 87.35% 92.70% +5.35%
==========================================
Files 36 36
Lines 2712 2756 +44
==========================================
+ Hits 2369 2555 +186
+ Misses 343 201 -142
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Each handler's failure branch now has a test: database errors on hiding, creating, editing, toggling and deleting, a duplicate exam or room that slips past the check, failures building rooms from sheets, and errors importing from the Canvas roster or previewing a layout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rors - Build redirect URLs before committing: a rollback expires every object, so with the database gone the redirect failed with a 500 - Report a non-UTF-8 room or student file plainly, by decoding uploads in one place that raises DataValidationError - Keep DataValidationError messages from the Canvas roster import - Only call an IntegrityError a duplicate when the duplicate is there after the rollback; any other broken constraint is unexpected - Name the room a room edit clashes with, and leave the clash to the commit instead of an autoflush while updating seats - Check for a duplicate exam inside the error handling, report an offering imported meanwhile, and share the room duplicate message Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Second review: - _commit_or_flash commits, or rolls back and reports a duplicate or an unexpected error with a reference; the handlers use it instead of their own copies of that block - _flash_unexpected_error rolls back too, so a failed query no longer leaves the transaction aborted for the next room of an import, and a failed seat update returns instead of committing and reporting twice - Only newly imported offerings count as duplicates, not hidden ones being shown again - Hiding reports success with the name read before the commit - After a failed commit, redirect instead of rendering a page that needs the database - One find_room lookup, shared by prepare_room and the duplicate check - prepare_seat reports non-numeric coordinates and counts, and reads rows shorter than the header Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Add imported offerings rather than bulk saving them: a bulk save inserts right away, so a course imported by someone else meanwhile failed outside the error handling with a 500 - Report a failure loading what deleting an exam or student takes with it, instead of a 500 - A room without a start time is never a duplicate: the database lets those share a name, so a broken constraint there is unexpected Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Closes #180
Handlers in
server/views.pyused to flash the exception text. For database errors, that text includes the SQL statement, its parameters and connection details, and flashes are stored in the session cookie, which is signed but not encrypted. The messages are now written by us. They name what failed and the exam, room or student involved, and include nothing from the exception.Changes
prepare_room._commit_or_flashcommits, or rolls back and reports why it couldn't. After the rollback it looks for the duplicate the commit clashed with, e.g. one saved by another request meanwhile: an exam, a room with a start time (naming the room it clashes with), or "Already imported: …" for newly imported offerings. If it doesn't find one, the failure is unexpected, so a bug isn't called a duplicate. The handlers use this helper instead of each having its own copy.DataValidationErrorandGcpErrormessages are still shown, prefixed with what failed (for example "Couldn't import room 'Soda 999': …"). This includes the Canvas roster import._flash_unexpected_errorrolls back, logs the traceback with an 8-character reference and flashes "Couldn't delete exam 'Midterm 1' due to an unexpected error (ref a1b2c3d4)." Because of the rollback, a failed query doesn't leave the transaction aborted (on Postgres) for the rest of the request, such as the next room of a master-sheet import.prepare_seatreports non-numeric coordinates and counts instead of failing unexpectedly, and reads rows that are shorter than the header.prepare_roomand the duplicate check share onefind_roomlookup.decode_csv_file). A file that isn't UTF-8 gets "Save the file as CSV with UTF-8 encoding".printis removed.Saving a room edit when the seats fail to update was there before this PR, and is filed as #184.
Tests
tests/unit/test_error_messages.pycovers every failure branch the PR touches:All 718 unit tests pass, and every line this PR changes is covered.
🤖 Generated with Claude Code