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
Explaining QueryCache queries throws an exception #4750
Comments
@mschulkind we could check if Could you please provide a minimal app that reproduces the issue? /cc @tenderlove |
I'll see if I can come up with something if you're still not convinced, but take a look at: You'll see that the object that makes its way into the queries collection for exec_explain is created on that line. Never is the :bind key filled in. The bug is either here not including :binds or the explain stuff not checking for nil. I'd guess this is because the cache only stories post-binded queries, so there are never any binds. You'll find that the queries logged by: Alternatively, I don't fully understand how the QueryCache works, but if the query is cached, why is the explainer ever even coming into play? |
@mschulkind I see, yes I think that analysis is enough. Yes, I believe the payload should get the bindings as well, I am fixing it. |
Awesome. Thanks for the fast fix. |
Thanks! I noticed this, and monkey patched in the new code (while i wait on rails3.2.2). |
Sure. Later we disabled EXPLAIN for cached queries. See 1e5cdbd. |
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:
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.
The text was updated successfully, but these errors were encountered: