Skip to content

Commit

Permalink
Fix load_async for null relations
Browse files Browse the repository at this point in the history
Fixes #50351
  • Loading branch information
lucasmazza committed Dec 13, 2023
1 parent ee65e97 commit c755144
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation.rb
Expand Up @@ -960,7 +960,7 @@ def exec_queries(&block)
def exec_main_query(async: false)
if @none
if async
return Promise::Complete.new([])
return FutureResult::Complete.new([])
else
return []
end
Expand Down
12 changes: 12 additions & 0 deletions activerecord/test/cases/relation/load_async_test.rb
Expand Up @@ -41,6 +41,18 @@ def test_scheduled?
assert_not_predicate deferred_posts, :scheduled?
end

def test_null_scheduled?
deferred_null_posts = Post.none.load_async
if in_memory_db?
assert_not_predicate deferred_null_posts, :scheduled?
else
assert_predicate deferred_null_posts, :scheduled?
end
assert_predicate deferred_null_posts, :loaded?
deferred_null_posts.to_a
assert_not_predicate deferred_null_posts, :scheduled?
end

def test_reset
deferred_posts = Post.where(author_id: 1).load_async
if in_memory_db?
Expand Down

0 comments on commit c755144

Please sign in to comment.