1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #27341 from richardmonette/fix-querycache-nil-dup

fix QueryCache nil dup
This commit is contained in:
Rafael França 2016-12-15 17:02:22 -05:00 committed by GitHub
commit b89f1aa760
5 changed files with 34 additions and 5 deletions

View file

@ -1,3 +1,13 @@
* Notifications see frozen SQL string.
Fixes #23774
*Richard Monette*
* RuntimeErrors are no longer translated to ActiveRecord::StatementInvalid.
*Richard Monette*
* Change the schema cache format to use YAML instead of Marshal.
*Kir Shatrov*

View file

@ -10,9 +10,9 @@ module ActiveRecord
def to_sql(arel, binds = [])
if arel.respond_to?(:ast)
collected = visitor.accept(arel.ast, collector)
collected.compile(binds, self)
collected.compile(binds, self).freeze
else
arel
arel.dup.freeze
end
end

View file

@ -598,7 +598,12 @@ module ActiveRecord
def translate_exception(exception, message)
# override in derived class
ActiveRecord::StatementInvalid.new(message)
case exception
when RuntimeError
exception
else
ActiveRecord::StatementInvalid.new(message)
end
end
def without_prepared_statement?(binds)

View file

@ -285,13 +285,13 @@ module ActiveRecord
unless current_adapter?(:PostgreSQLAdapter)
def test_log_invalid_encoding
error = assert_raise ActiveRecord::StatementInvalid do
error = assert_raises RuntimeError do
@connection.send :log, "SELECT 'ы' FROM DUAL" do
raise "ы".force_encoding(Encoding::ASCII_8BIT)
end
end
assert_not_nil error.cause
assert_not_nil error.message
end
end

View file

@ -202,6 +202,20 @@ class QueryCacheTest < ActiveRecord::TestCase
ActiveSupport::Notifications.unsubscribe subscriber
end
def test_query_cache_does_not_allow_sql_key_mutation
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |_, _, _, _, payload|
payload[:sql].downcase!
end
assert_raises RuntimeError do
ActiveRecord::Base.cache do
assert_queries(1) { Task.find(1); Task.find(1) }
end
end
ensure
ActiveSupport::Notifications.unsubscribe subscriber
end
def test_cache_is_flat
Task.cache do
assert_queries(1) { Topic.find(1); Topic.find(1); }