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

Raise KeyError when specifying non existent column #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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