Conversation
Why these changes are being introduced: `ThesisController#deleted_file_list` calls `.blob` on a potentially nil Active Storage attachment. The processing form can trigger a race condition when a background process deletes a file that is still visible on the form. If a user attempts to delete that file and the attachment no longer exists, the app throws a 422 error. Relevant ticket(s): - [USE-710](https://mitlibraries.atlassian.net/browse/ETD-710) How this addresses that need: This adds a guard clause to check for the presence of the attachment before calling `.blob`. Side effects of this change: None.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Add coverage verifying stale attachment submissions complete without a 422/error.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Guards thesis processing against deleted Active Storage attachments.
Changes:
- Checks attachment existence before accessing its blob.
- Skips stale attachment entries safely.
File summaries
| File | Description |
|---|---|
app/controllers/thesis_controller.rb |
Adds a nil attachment guard in deleted_file_list. |
The stale-attachment regression path lacks controller test coverage and should be tested.
Review details
Suppressed comments (1)
app/controllers/thesis_controller.rb:182
- This guard only skips building the flash-message entry; the same stale
idremains inthesis_paramsand is passed tothesis.updateat line 124. BecauseThesisenablesaccepts_nested_attributes_for :files_attachments, Rails can still raiseActiveRecord::RecordNotFoundwhile applying_destroyfor an attachment that disappeared, so the reported 422 race is not fully prevented. Remove or ignore missing attachment entries before the update (and add a regression test for the stale id).
next unless attachment
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+181
to
+182
| attachment = ActiveStorage::Attachment.find_by(id: file['id']) | ||
| next unless attachment |
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.
Why these changes are being introduced:
ThesisController#deleted_file_listcalls.blobon a potentially nil Active Storage attachment.The processing form can trigger a race condition
when a background process deletes a file that is
still visible on the form. If a user attempts to
delete that file and the attachment no longer
exists, the app throws a 422 error.
Relevant ticket(s):
How this addresses that need:
This adds a guard clause to check for the presence of the attachment before calling
.blob.Side effects of this change:
None.
Developer
Accessibility
New ENV
Approval beyond code review
Additional context needed to review
E.g., if the PR includes updated dependencies and/or data
migration, or how to confirm the feature is working.
Code Reviewer
Code
added technical debt.
Documentation
(not just this pull request message).
Testing