Skip to content

Conversation

@malclocke
Copy link

We have a setup where we occasionally try to bulk import from a database with a schema that is out of sync with the target. If the source database has columns that do not exist on the target a more meaningful error from bulk_import would help us debug.

This change causes the code to short circuit with a KeyError if a non existent column is specified in the initializer.

Error before:

Error:
BulkInsertWorkerTest#test_meaningul_error_is_presented_if_specifying_non_existant_columns:
NoMethodError: undefined method `name' for nil:NilClass
    .../bulk_insert/lib/bulk_insert/worker.rb:52:in `block in add'
    .../bulk_insert/lib/bulk_insert/worker.rb:51:in `map'
    .../bulk_insert/lib/bulk_insert/worker.rb:51:in `with_index'
    .../bulk_insert/lib/bulk_insert/worker.rb:51:in `add'
    .../bulk_insert/test/bulk_insert/worker_test.rb:280:in `block in <class:BulkInsertWorkerTest>'

Error after:

Error:
BulkInsertWorkerTest#test_meaningul_error_is_presented_if_specifying_non_existant_columns:
KeyError: key not found: "no_such_column"
    .../bulk_insert/lib/bulk_insert/worker.rb:28:in `fetch'
    .../bulk_insert/lib/bulk_insert/worker.rb:28:in `block in initialize'
    .../bulk_insert/lib/bulk_insert/worker.rb:28:in `map'
    .../bulk_insert/lib/bulk_insert/worker.rb:28:in `initialize'
    .../bulk_insert/test/bulk_insert/worker_test.rb:273:in `new'
    .../bulk_insert/test/bulk_insert/worker_test.rb:273:in `block in <class:BulkInsertWorkerTest>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant