Description
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.