Skip to content

Commit d0c6b96

Browse files
authored
Merge pull request rails#54645 from fatkodima/fix-async-aggregations-for-contradictions
Fix async aggregation queries to return promise for contradicted queries
2 parents 13edb64 + 9d19fd6 commit d0c6b96

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

activerecord/lib/active_record/relation/calculations.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,11 @@ def execute_simple_calculation(operation, column_name, distinct) # :nodoc:
497497
end
498498

499499
query_result = if relation.where_clause.contradiction?
500-
ActiveRecord::Result.empty
500+
if @async
501+
FutureResult.wrap(ActiveRecord::Result.empty)
502+
else
503+
ActiveRecord::Result.empty
504+
end
501505
else
502506
skip_query_cache_if_necessary do
503507
model.with_connection do |c|

activerecord/test/cases/calculations_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,13 @@ def test_count_with_block
755755
assert_equal 4, Account.count { |account| account.credit_limit.modulo(10).zero? }
756756
end
757757

758+
def test_count_with_empty_in
759+
assert_queries_count(0) do
760+
assert_equal 0, Topic.where(id: []).count
761+
assert_async_equal 0, Topic.where(id: []).async_count
762+
end
763+
end
764+
758765
def test_should_sum_expression
759766
assert_equal 636, Account.sum("2 * credit_limit")
760767
end

0 commit comments

Comments
 (0)