Skip to content
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

Lookup existing attendances by only session and teacher, then set enr… #15751

Merged
merged 1 commit into from Jun 12, 2017

Conversation

aoby
Copy link
Contributor

@aoby aoby commented Jun 9, 2017

…ollment after, to reduce chance of RecordNotUnique error

Errors in the wild:
https://app.honeybadger.io/projects/3240/faults/33792540
https://app.honeybadger.io/projects/3240/faults/33760831

ActiveRecord::RecordNotUnique: Mysql2::Error: Duplicate entry... for key 'index_pd_attendances_on_pd_session_id_and_teacher_id': INSERT INTO `pd_attendances`

attendance.rb  63  block in find_restore_or_create_by!(...)
attendance.rb  61  find_restore_or_create_by!(...)
workshop_attendance_controller.rb  67  create(...)
...

I'm not actually sure what's causing this error, but I suspect maybe there's an existing (deleted) entry with either a different enrollment or no enrollment, and this attempt to recreate it with a new enrollment id is conflicting. In both cases, I logged in and was able to set attendance successfully in the UI.

This PR separates the lookup (now just teacher and session, the unique fields for the index) from updating the enrollment. If my hunch is wrong, this shouldn't cause any problems. It will still result in the same outcome, and we were already making a second SQL call to update the marked_by_user.

…ollment after, to reduce chance of RecordNotUnique error
@aoby aoby merged commit 80ecf88 into staging Jun 12, 2017
@aoby aoby deleted the pd-attendance-set-enrollment-after-lookup branch June 12, 2017 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants