rails/rails — Issue #4750: Explaining QueryCache queries throws an exception
Author: mschulkind
Created: 2012-01-30 03:39:04+00:00
State: open

I'm pretty sure I've narrowed this down to a real fix, but I figured I'd file a bug report instead of a pull request since I'm not super familiar with rails internals.

Here's the error I get, reproduced on 3.2.0 and 3.2.1:

```
#
/home/matt/.rvm/gems/ruby-1.9.2-p290@gojotter/gems/activerecord-3.2.0/lib/active_record/explain.rb:62:in `block (2 levels) in exec_explain'
/home/matt/.rvm/gems/ruby-1.9.2-p290@gojotter/gems/activerecord-3.2.0/lib/active_record/explain.rb:57:in `tap'
/home/matt/.rvm/gems/ruby-1.9.2-p290@gojotter/gems/activerecord-3.2.0/lib/active_record/explain.rb:57:in `block in exec_explain'
/home/matt/.rvm/gems/ruby-1.9.2-p290@gojotter/gems/activerecord-3.2.0/lib/active_record/explain.rb:56:in `map'
/home/matt/.rvm/gems/ruby-1.9.2-p290@gojotter/gems/activerecord-3.2.0/lib/active_record/explain.rb:56:in `exec_explain'
/home/matt/.rvm/gems/ruby-1.9.2-p290@gojotter/gems/activerecord-3.2.0/lib/active_record/explain.rb:32:in `logging_query_plan'
```

The problem seems to be here:
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/explain.rb#L58
This line only checks if bind is empty?, but not for nil, so it barfs here.

It looks like these queries are generated in two places:
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb#L274
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb#L71

The latter doesn't always store a value for binds. This is what causes problems.