Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

undefined method `name' for nil:NilClass in arel 2.0.10 #124

Open
chrisbloom7 opened this Issue Jun 8, 2012 · 2 comments

Comments

Projects
None yet
2 participants

I have a Rails app (currently on 3.0.12, but have also tested this on 3.0.13) with a custom rake task:

namespace :db do
  task :bootstrap => ["db:drop", "db:create", "db:migrate", "db:seed"]
end

When I run it I get an error "undefined method 'name' for nil:NilClass". It is triggered from a line that calls save on an object, but the actual error seems to be coming from arel-2.0.10/lib/arel/visitors/to_sql.rb:56.

When I run all these tasks in tandem in the command line I do not get the error:

rake db:drop && rake db:create && rake db:migrate && rake db:seed

I'm not familiar enough with the internals of rake tasks to understand what the environmental differences might be that would lead to this error in the former case but not the latter, and thus if it is an error in Arel that could be addressed or an error in Rake. Any feedback would be helpful.

Full trace follows:

undefined method `name' for nil:NilClass
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activesupport-3.0.13/lib/active_support/whiny_nil.rb:48:in `method_missing'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/arel-2.0.10/lib/arel/visitors/to_sql.rb:56:in `block in visit_Arel_Nodes_InsertStatement'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/arel-2.0.10/lib/arel/visitors/to_sql.rb:55:in `map'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/arel-2.0.10/lib/arel/visitors/to_sql.rb:55:in `visit_Arel_Nodes_InsertStatement'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/arel-2.0.10/lib/arel/visitors/visitor.rb:15:in `visit'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/arel-2.0.10/lib/arel/visitors/visitor.rb:5:in `accept'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/arel-2.0.10/lib/arel/visitors/to_sql.rb:18:in `block in accept'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:111:in `with_connection'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/arel-2.0.10/lib/arel/visitors/to_sql.rb:16:in `accept'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/arel-2.0.10/lib/arel/tree_manager.rb:20:in `to_sql'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/arel-2.0.10/lib/arel/select_manager.rb:217:in `insert'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/relation.rb:14:in `insert'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/persistence.rb:281:in `create'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/timestamp.rb:47:in `create'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/callbacks.rb:277:in `block in create'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activesupport-3.0.13/lib/active_support/callbacks.rb:414:in `_run_create_callbacks'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/callbacks.rb:277:in `create'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/persistence.rb:257:in `create_or_update'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/callbacks.rb:273:in `block in create_or_update'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activesupport-3.0.13/lib/active_support/callbacks.rb:434:in `_run_save_callbacks'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/callbacks.rb:273:in `create_or_update'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/persistence.rb:60:in `save!'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/validations.rb:49:in `save!'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/transactions.rb:245:in `block in save!'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/transactions.rb:207:in `transaction'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/newrelic_rpm-3.1.2/lib/new_relic/agent/method_tracer.rb:491:in `block in transaction_with_trace_ActiveRecord_self_name_transaction'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/newrelic_rpm-3.1.2/lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/newrelic_rpm-3.1.2/lib/new_relic/agent/method_tracer.rb:486:in `transaction_with_trace_ActiveRecord_self_name_transaction'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/transactions.rb:245:in `save!'
db/seeds/development/brands.seeds.rb:49:in `block (2 levels) in <top (required)>'
db/seeds/development/brands.seeds.rb:12:in `times'
db/seeds/development/brands.seeds.rb:12:in `block in <top (required)>'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activerecord-3.0.13/lib/active_record/transactions.rb:207:in `transaction'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/newrelic_rpm-3.1.2/lib/new_relic/agent/method_tracer.rb:491:in `block in transaction_with_trace_ActiveRecord_self_name_transaction'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/newrelic_rpm-3.1.2/lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/newrelic_rpm-3.1.2/lib/new_relic/agent/method_tracer.rb:486:in `transaction_with_trace_ActiveRecord_self_name_transaction'
db/seeds/development/brands.seeds.rb:11:in `<top (required)>'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activesupport-3.0.13/lib/active_support/dependencies.rb:236:in `load'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activesupport-3.0.13/lib/active_support/dependencies.rb:236:in `block in load'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activesupport-3.0.13/lib/active_support/dependencies.rb:225:in `block in load_dependency'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activesupport-3.0.13/lib/active_support/dependencies.rb:597:in `new_constants_in'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activesupport-3.0.13/lib/active_support/dependencies.rb:225:in `load_dependency'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/activesupport-3.0.13/lib/active_support/dependencies.rb:236:in `load'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/seedbank-0.0.9/lib/seedbank/dsl.rb:19:in `block in define_seed_task'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/chrisbloom7/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/chrisbloom7/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/chrisbloom7/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/chrisbloom7/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/bin/rake:19:in `load'
/Users/chrisbloom7/.rvm/gems/ruby-1.9.2-p180@mms/bin/rake:19:in `<main>'
Tasks: TOP => db:bootstrap => db:seed => db:seed:development => db:seed:development:brands

Here is a report of the same issue coming from the same line in Arel 2.0.9 from a similar string of rake tasks: http://rorguide.blogspot.com/2011/04/getting-undefined-method-name-for.html

avit commented Jul 20, 2012

Wild-arsed guess: the database columns must be present for your ActiveRecord models to pick up. If the initial state is "no-database" and subsequent rake tasks call on models, then it would choke on nils. I see brands.seeds.rb in the stack trace, so I assume it got that far... Try ActiveRecord::Base.reset_column_information before calling on models in your seeds and see if it cures it.

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