Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Randomly raised nil.collect! in find_by_sql #9003

Closed
puffy opened this Issue · 6 comments

3 participants

@puffy

There is a problem while running cucumber features (originally started in cucumber issues). Sometimes ActiveRecord raised nil.collect!.

This problem began after we upgrading from ruby enterprise to 1.9 (currently using 1.9.3-p362). It raised only in test environment, in production and development we don't see it ever.
In all environments used PostgreSQL.

Backtrace chunk from one of the raises:

And I have new user order with line items                  # features/step_definitions/orders_steps.rb:1
  You have a nil object when you didn't expect it!
  You might have expected an instance of Array.
  The error occurred while evaluating nil.collect! (NoMethodError)
  /home/ssherif/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.19/lib/active_record/base.rb:473:in `find_by_sql'
  /home/ssherif/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.19/lib/active_record/relation.rb:64:in `to_a'
  /home/ssherif/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.19/lib/active_record/relation/finder_methods.rb:143:in `all'
  /home/ssherif/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.19/lib/active_record/associations/association_collection.rb:70:in `block in find'
  /home/ssherif/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.19/lib/active_record/base.rb:1131:in `with_scope'
  /home/ssherif/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.19/lib/active_record/associations/association_proxy.rb:212:in `with_scope'
  /home/ssherif/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.19/lib/active_record/associations/association_collection.rb:63:in `find'
  /home/ssherif/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.19/lib/active_record/associations/association_collection.rb:468:in `find_target'
  /home/ssherif/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.19/lib/active_record/associations/association_collection.rb:410:in `load_target'
  /home/ssherif/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.19/lib/active_record/associations/association_proxy.rb:117:in `_load'
  /home/ssherif/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.19/lib/active_record/associations/association_proxy.rb:124:in `reload'
  /home/ssherif/app/app/models/order.rb:608:in `update_adjustments'
  /home/ssherif/app/app/models/order.rb:252:in `update!'

It's hard to understand what going wrong, but I doubt for query.cache.rb and #cache_sql method, where it's quite possible return nil result instead of Array.

This problem is very similar to #5471.

@steveklabnik
Collaborator

We need a way to reproduce this, there's almost no way to tell why this error is happening. Can you upload an application that reproduces this, please?

@pixeltrix
Owner

Seems somewhat related to #2943 and cucumber/cucumber-rails#166 - is this running javascript enabled features?

@puffy

@pixeltrix very seems.
We used capybara-webkit as a default driver and database cleaner with transaction strategy.
Now I try to change cleaning strategy to truncation like recommended in cucumber/cucumber-rails#166#issuecomment-2156610

As I understood the problem more of a feature of running capybara with rails transactions than a bag?

@pixeltrix
Owner

I think the problem stems from trying to share the database connection amongst two threads - does it work correctly now?

@puffy

I write about results after 2-3 days testing

@puffy

Finally my problem is fixed after changing database_cleaner strategy to :truncation and setting ActiveRecord::Base.shared_connection = nil in cucumber before hook.

@puffy puffy closed this
@puffy puffy referenced this issue in cucumber/cucumber-ruby
Closed

Randomly raised nil.collect in single scenario #353

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.