Skip to content

Commit

Permalink
make sure strings don't sneak into bulk imports
Browse files Browse the repository at this point in the history
closes FOO-1366
flag=none

TEST PLAN:
  1) run sis enrollments import that adds a string error
     to "messages"
  2) it gets inserted as a SisBatchError, no explosion

Change-Id: I87f54f5300448c5ed005612c44639d33bc4d41c7
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/255603
Tested-by: Service Cloud Jenkins <[email protected]>
Reviewed-by: Simon Williams <[email protected]>
QA-Review: Simon Williams <[email protected]>
Product-Review: Simon Williams <[email protected]>
  • Loading branch information
evizitei committed Dec 18, 2020
1 parent c33c714 commit d66b291
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/sis/csv/enrollment_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@ def process(csv, index=nil, count=nil)
end
end
end
SisBatch.bulk_insert_sis_errors(messages)
persist_errors(csv, messages, @batch)
count
end

def persist_errors(csv, messages, batch)
errors = messages.map do |message|
(message.is_a? SisBatchError) ? message : SisBatch.build_error(csv, message, sis_batch: @batch)
end
SisBatch.bulk_insert_sis_errors(errors)
end

private
def create_enrollment(row, messages, csv: nil)
enrollment = SIS::Models::Enrollment.new(
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/sis/csv/enrollment_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,16 @@
)
end

describe "#persist_errors" do
it "gracefully handles string errors" do
batch = Account.default.sis_batches.create!
csv = double(root_account: Account.default, batch: batch, :[] => nil)
importer = SIS::CSV::EnrollmentImporter.new(csv)
importer.persist_errors(csv, ['a string error message'], batch)
expect(batch.sis_batch_errors.count).to eq(1)
end
end

it 'should only queue up one recache_grade_distribution job per course' do
Course.create!(account: @account, sis_source_id: 'C001', workflow_state: 'available')
user_with_managed_pseudonym(account: @account, sis_user_id: 'U001')
Expand Down

0 comments on commit d66b291

Please sign in to comment.