Repository navigation
Dont create students roles with null user_id - #1108
Open
zetter-rpf wants to merge 2 commits into
Open
zetter-rpf wants to merge 2 commits into
zetter-rpf wants to merge 2 commits into
Conversation
zetter-rpf
marked this pull request as ready for review
November 12, 2026 15:34
ApprovabilityVerdict: Needs Human Approval Macroscope's review found this PR requires human approval — The change prevents failed student creations from producing roles and adds a database-wide NOT NULL constraint. Confirm production roles—including archived records—contain no null user IDs before migration; the reported check excludes archived roles, leaving deployment readiness unresolved. Needs human approval because:
You can add or adjust custom eligibility rules. Learn more. |
Test coverage94.18% line coverage reported by SimpleCov. |
Previously we were incorrectly assuming that all records in the profile response where successful student creations. However, some records may be errors. These errors don't have a student id and have a success: false as well as an error row (see [1]) This caused the creation of students with a `null` user_id, which later caused errors. Make sure we only log successful creations. I'm logging the errors so we can see what caused them. There's a try/catch in profile with a wide scope so it's not clear what's gone wrong. I'm assuming it might be a failed creation due to a concurrency issue. [1] - https://github.com/RaspberryPiFoundation/profile/blame/main/app/lib/createGoogleSSOStudents.js Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
We were incorrectly handling errors from creating students and trying to create students without an id (see previous commit for details. Since this was a bulk create, we bypassed the model validation This is a extra safeguard to prevent this happening again. I've checked and we have none in our database at the moment - `Role.where(user_id: null).count`
zetter-rpf
force-pushed
the
dont-create-students-with-null-user-id
branch
from
November 12, 2026 15:45
256b66c to
b661415
Compare
This branch was successfully deployed
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
What's changed?
See commits for more
Steps to perform after deploying to production
Check that the migration will still work by running
Role.unscoped.where(user_id: nil).count