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

Avoid running async queries on null relations

Calling `load_async` on a null relation was executing the fallback
`WHERE 1=0` query, since it doesn't go through `exec_queries`.

Since 2a90104989, `exec_queries` is
implemented in terms of `exec_main_query`, so we only need to override
that one method.

We can also stop assigning `@records`, as that now happens in `load`
since 847643a55a.
This commit is contained in:
Eugene Kenny 2021-05-17 21:34:41 +01:00
parent 5ddff2beb1
commit cb670c5c98
2 changed files with 8 additions and 2 deletions

View file

@ -56,8 +56,8 @@ module ActiveRecord
end end
private private
def exec_queries def exec_main_query(async: false)
@records = [].freeze [].freeze
end end
end end
end end

View file

@ -28,6 +28,12 @@ class NullRelationTest < ActiveRecord::TestCase
end end
end end
def test_async_query_on_null_relation
assert_no_queries do
assert_equal [], Developer.none.load_async.load
end
end
def test_none_chained_to_methods_firing_queries_straight_to_db def test_none_chained_to_methods_firing_queries_straight_to_db
assert_no_queries do assert_no_queries do
assert_equal [], Developer.none.pluck(:id, :name) assert_equal [], Developer.none.pluck(:id, :name)