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
Disable query cache for lock queries #6985
Disable query cache for lock queries #6985
Conversation
@@ -83,6 +83,14 @@ def cache_sql(sql, binds) | |||
result.collect { |row| row.dup } | |||
end | |||
end | |||
|
|||
def locked?(arel) | |||
if arel.respond_to?(:locked) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there some case where locked
is not defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sometimes the arel
is actually a String
.
Without the check QueryCacheTest#test_cache_does_not_wrap_string_results_in_arrays
was failing.
Disable query cache for lock queries
@rafaelfranca - should this also be ported to the rails 3 branch? |
@jjb I can backport to 3-2-stable, but I want to confirm with @tenderlove first. |
Disable query cache for lock queries Conflicts: activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
whoo hoo! |
Line 83 causes an NoMethodFound exception when there is a 'locked' scope defined on a model. The respond_to? call returns true but the method is not found. Perhaps having a scope named 'locked' is a bad idea anyway, but that isn't documented as far as I know. |
@nragaz Agreed on naming. Just got bitten by this when upgrading Rails. It has a weird interaction with Draper. |
@ihoka oh? |
@steveklabnik yes. Draper uses method_missing and respond_to? to delegate to the model. The issue I ran into was triggered by calling a method on the wrapped model within a decorator, which internally uses associations (has_one in my case). When doing so, it spits out an "undefined method `locked' for #Class:0x007f82fb067068", like this: https://gist.github.com/7498247d20ecd191d77e. I spent a bunch of time chasing the cause, and finally ended up renaming my "locked" named scope to something else. |
Roger, okay. So not really something I could have fixed. |
@steveklabnik I think the point is that suddenly relying on the behaviour of a method named |
@nragaz in this case I'm speaking as the Draper maintainer, not as someone who works on Rails. I agree that |
@steveklabnik Ah, cool. I didn't realize you were the Draper maintainer. On 2012-08-14, at 1:13 PM, Steve Klabnik notifications@github.com wrote:
|
I ran into this exact problem as well and have to rename many scopes. Would it be possible to add something similar to DangerousAttributeError for scopes? |
One of the possibles solution is add a method |
Would be nice to get this fixed, or at least find a way to provide a slightly less obscure error message. Just got bitten by this. |
Wasted a bunch of time on this. A better error is definitely needed :( |
|
||
def locked?(arel) | ||
if arel.respond_to?(:locked) | ||
arel.locked |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI we have a scope called locked and this is blowing up ;)
Query caching should be disabled for queries asking for a pessimistic lock. Otherwise the lock query may not reach the database, thus breaking the expected functionality.
Fixes #867