Defensive serving Scratch projects#922
Open
abcampo-iry wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the Scratch projects API endpoint so malformed/historical Scratch projects (missing an associated scratch_component) are treated as 404 Not Found instead of raising a NoMethodError when rendering the Scratch JSON payload.
Changes:
- Require a Scratch project to have an associated
scratch_componentwhen loading via the Scratch projects controller. - Add a request spec ensuring a Scratch project without a Scratch component returns
404 Not Found.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| spec/features/scratch/showing_a_scratch_project_spec.rb | Adds coverage for the “missing scratch component returns 404” behavior. |
| app/controllers/api/scratch/projects_controller.rb | Makes load_project enforce presence of scratch_component via an inner join, preventing nil dereference in show. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Test coverage92.18% line coverage reported by SimpleCov. |
91823b6 to
d74b1a2
Compare
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.
Status
Points for consideration
scratch_components. This uses the existing indexedproject_idand should have small to none impact.What’s changed?
Approached to fix Sentry issue.
Requires a Scratch project to have an associated Scratch component when loading it through the Scratch projects endpoint.
Returns the existing
404 Not Foundresponse for projects in this invalid state instead of raising:Adds a request spec covering a Scratch project without a Scratch component.
Valid Scratch projects are unaffected.
Steps to perform after deploying to production
None. This change does not require a migration, data cleanup, or Rake task. Existing malformed records will be handled safely by the endpoint.