seamusabshere / data_miner

Download, unpack from a ZIP/TAR/GZ/BZ2 archive, parse, correct, convert units and import Google Spreadsheets, XLS, ODS, XML, CSV, HTML, etc. into your ActiveRecord models. Uses RemoteTable gem internally.
MIT License
302 stars 18 forks source link

Example produces undefined method for nil exception #17

Closed chrisle closed 12 years ago

chrisle commented 12 years ago

I'm taking this gem for a test drive. Looks really interesting!

Environment

Ruby 1.9.3p194. Rails 3.2.6.

Steps to recreate:

  1. I created a new rails application
  2. Added mysql2, data_miner, and unicode_utils to the Gemfile and bundle installed
  3. Created app/models/country.rb and pasted your example in.
  4. Manually created a "countries" table in MySQL
  5. Opened up the rails console, and typed "Country.run_data_miner!"

I got the following error. I also tried this in an existing app and got the same error.

Stacktrace

1.9.3p194 :001 > Country.run_data_miner!
   (0.2ms)  SELECT COUNT(*) FROM `countries` 
   (0.1ms)  BEGIN
  SQL (0.3ms)  INSERT INTO `data_miner_runs` (`aasm_state`, `created_at`, `error`, `model_name`, `row_count_after`, `row_count_before`, `stopped_at`, `updated_at`) VALUES ('limbo', '2012-07-12 13:28:46', NULL, 'Country', NULL, 0, NULL, '2012-07-12 13:28:46')
   (0.4ms)  COMMIT
   (0.1ms)  BEGIN
   (1.5ms)  UPDATE `data_miner_runs` SET `error` = 'undefined method `type\' for nil:NilClass\n/Users/chrisle/.rvm/gems/ruby-1.9.3-p194@test_drive_data_mining/gems/data_miner-2.3.4/lib/data_miner/attribute.rb:357:in `boolean_column?\'\n/Users/chrisle/.rvm/gems/ruby-1.9.3-p194@test_drive_data_mining/gems/data_miner-2.3.4/lib/data_miner/attribute.rb:268:in `read\'\n/Users/chrisle/.rvm/gems/ruby-1.9.3-  ...
   (1.0ms)  COMMIT
   (0.1ms)  SELECT COUNT(*) FROM `countries` 
   (0.0ms)  BEGIN
   (0.2ms)  UPDATE `data_miner_runs` SET `row_count_after` = 0, `stopped_at` = '2012-07-12 13:28:47', `updated_at` = '2012-07-12 13:28:47' WHERE `data_miner_runs`.`id` = 3
   (0.4ms)  COMMIT
NoMethodError: undefined method `type' for nil:NilClass
    from /Users/chrisle/.rvm/gems/ruby-1.9.3-p194@test_drive_data_mining/gems/data_miner-2.3.4/lib/data_miner/attribute.rb:357:in `boolean_column?'
    from /Users/chrisle/.rvm/gems/ruby-1.9.3-p194@test_drive_data_mining/gems/data_miner-2.3.4/lib/data_miner/attribute.rb:268:in `read'
    from /Users/chrisle/.rvm/gems/ruby-1.9.3-p194@test_drive_data_mining/gems/data_miner-2.3.4/lib/data_miner/step/import.rb:92:in `block (2 levels) in start'
    from /Users/chrisle/.rvm/gems/ruby-1.9.3-p194@test_drive_data_mining/gems/remote_table-2.0.2/lib/remote_table.rb:432:in `block (2 levels) in each'
    from /Users/chrisle/.rvm/gems/ruby-1.9.3-p194@test_drive_data_mining/gems/remote_table-2.0.2/lib/remote_table.rb:421:in `each'
    from /Users/chrisle/.rvm/gems/ruby-1.9.3-p194@test_drive_data_mining/gems/remote_table-2.0.2/lib/remote_table.rb:421:in `block in each'
    from /Users/chrisle/.rvm/gems/ruby-1.9.3-p194@test_drive_data_mining/gems/remote_table-2.0.2/lib/remote_table/delimited.rb:50:in `block in _each' 
....

Have you seen this before?

seamusabshere commented 12 years ago

the next version of the gem will tell you if a column doesn't exist - which is i think what happened here.

please let me know if using the new example from the readme fixed the issue.

chrisle commented 12 years ago

Works! It works when I had nothing in the database. Here is the example:

Loading development environment (Rails 3.2.6)
1.9.3p194 :001 > Country.run_data_miner!
   (8.2ms)  CREATE TABLE `data_miner_runs` (`model_name` varchar(255), `aasm_state` varchar(255), `created_at` datetime, `stopped_at` datetime, `updated_at` datetime, `error` text, `row_count_before` int(11), `row_count_after` int(11), `id` int(11) DEFAULT NULL auto_increment PRIMARY KEY) ENGINE=InnoDB
   (9.8ms)  CREATE INDEX `index_data_miner_runs_on_model_name` ON `data_miner_runs` (`model_name`)
   (8.0ms)  CREATE INDEX `index_data_miner_runs_on_aasm_state` ON `data_miner_runs` (`aasm_state`)
   (0.0ms)  BEGIN
  SQL (0.6ms)  INSERT INTO `data_miner_runs` (`aasm_state`, `created_at`, `error`, `model_name`, `row_count_after`, `row_count_before`, `stopped_at`, `updated_at`) VALUES ('limbo', '2012-07-12 17:01:10', NULL, 'Country', NULL, NULL, NULL, '2012-07-12 17:01:10')
   (0.2ms)  COMMIT
   (3.1ms)  CREATE TABLE `countries` (`iso_3166_code` varchar(255) PRIMARY KEY, `iso_3166_numeric_code` int(11), `iso_3166_alpha_3_code` varchar(255), `name` varchar(255)) ENGINE=InnoDB
   (0.0ms)  BEGIN
   (0.2ms)  UPDATE `data_miner_runs` SET `aasm_state` = 'succeeded', `updated_at` = '2012-07-12 17:01:11' WHERE `data_miner_runs`.`id` = 1
   (0.4ms)  COMMIT
   (0.2ms)  SELECT COUNT(*) FROM `countries` 
   (0.1ms)  BEGIN
   (0.2ms)  UPDATE `data_miner_runs` SET `row_count_after` = 249, `stopped_at` = '2012-07-12 17:01:11', `updated_at` = '2012-07-12 17:01:11' WHERE `data_miner_runs`.`id` = 1
   (0.2ms)  COMMIT
 => #<DataMiner::Run model_name: "Country", aasm_state: "succeeded", created_at: "2012-07-12 17:01:10", stopped_at: "2012-07-12 17:01:11", updated_at: "2012-07-12 17:01:11", error: nil, row_count_before: nil, row_count_after: 249, id: 1> 
1.9.3p194 :002 >