Skip to content

NoMethodError exception in SchoolStudent::List#list_students #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
chrisroos opened this issue May 21, 2025 · 2 comments · May be fixed by #554
Open

NoMethodError exception in SchoolStudent::List#list_students #548

chrisroos opened this issue May 21, 2025 · 2 comments · May be fixed by #554
Assignees
Labels
bug Something isn't working tech debt

Comments

@chrisroos
Copy link
Contributor

While clearing out exceptions for experience-cs I noticed this exception in editor-api which appears to reveal a bug in the code:

NoMethodError

undefined method `id' for nil:NilClass (NoMethodError)

        ProfileApiClient.list_school_students(token:, school_id: school.id, student_ids:).map do |student|
                                                                       ^^^

The error is caused when the school passed in to #list_students is nil, which appears to be possible because of this line in Project.users. The pluck(:school_id) returns an array of all school_ids for the current Project scope. My guess is that in some cases the first entry in the array of school_ids is nil, which means we execute School.find_by(id: nil) which returns nil. An alternative guess is that the school_id isn't nil but somehow doesn't correspond to an ID in the schools table. I think the second guess is less likely due to the foreign key constraint on projects and schools but I don't know for sure.

@chrisroos
Copy link
Contributor Author

Flagging this for your attention, @adrian-rpf. There are 18k instances of this in Sentry so it might be worth investigating (assuming you haven't already) in case it's causing a real problem for users.

@adrian-rpf adrian-rpf added bug Something isn't working tech debt labels May 23, 2025
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tech debt
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants