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

Uploading new course groups while there are in-flight requests breaks queue with 'not found' error #199

Open
mterwill opened this issue Mar 1, 2021 · 1 comment
Labels

Comments

@mterwill
Copy link
Owner

mterwill commented Mar 1, 2021

When new course groups are uploaded, we wipe out any existing groups and create all new ones:

def groups
if request.method == 'GET'
@course_group_string = @course.get_group_string
return
end
begin
ActiveRecord::Base.transaction do
@course.course_groups.destroy_all
params[:groups].strip().split("\n").each do |emails_csv|
emails = emails_csv.strip().split(',')
next unless emails.any?
group = @course.course_groups.create!
emails.map do |email|
group.students << User.find_or_create_by(email: email.strip())
end
end
end
redirect_to admin_course_url(@course)
rescue ActiveRecord::RecordInvalid => err
@course_group_string = params[:groups]
@err = err
render :groups
end
end

If this is done mid-semester with active requests, since we denormalize course_group_id onto the request at submit time, any existing course group IDs become invalid. We're not using foreign keys in our schema (I'm not sure why) so this ends up propagating up to a runtime error when we try to resolve groups for open requests: Couldn't find CourseGroup with 'id'.

@mterwill mterwill added the bug label Mar 1, 2021
@mterwill
Copy link
Owner Author

mterwill commented Mar 1, 2021

ad-hoc fix with

mysql> update course_queue_entries set course_group_id = NULL where course_queue_id = 753 and resolved_at is null;
Query OK, 13 rows affected (0.05 sec)
Rows matched: 13  Changed: 13  Warnings: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant