rails: Rails 7.1.3: async_count returns a completed Promise instead of the value

Steps to reproduce

Following this issue https://github.com/rails/rails/issues/50399

I updated my application to Rails 7.1.3 and now async_count returns #<ActiveRecord::Promise status=complete> instead of the value directly

I created a reproduction repo (same as last time) and updated the case

https://github.com/guillaumebriday/async_count_bug

ping @fatkodima

Actual behavior

We need to use .value.value to get the actual value instead of .value only as it was before

Screenshot 2024-01-16 at 21 05 29

System configuration

Rails version: 7.1.3

Ruby version: 3.3.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 7
  • Comments: 18 (17 by maintainers)

Commits related to this issue

Most upvoted comments

Is there any workaround in the meantime?

Use this in the Gemfile:

gem "rails", github: "rails/rails", branch: "7-1-stable"

Yes, that is correct.

I am facing the same problem with : gem "rails", github: "fatkodima/rails", branch: "fix-caching-async-queries"

user =               User.async_count
user                 #<ActiveRecord::Promise status=complete>
user.value           #<ActiveRecord::Promise status=complete>
user.value.value     0

I may found a fix https://github.com/rails/rails/pull/50778/files/642633a76394b055091897d333b420bb4e0b79e4

Ah, thanks for clarifying, I misunderstood the branch numbering.

So it sounds like…

  • It is an actual regression between 7.1.2 and 7.1.3
  • It’s fixed by that linked PR
  • It’s backported to 7-1-stable branch and will be fixed in a future 7.1.4 and stay fixed in 7.2

?

Assuming https://github.com/rails/rails/pull/50778 is the relevant fix … it has a comment at bottom of PR that it’s been backported.

If the FutureResult.wrap method’s presence is the relevant part of the fix…

They do have the changes from https://github.com/rails/rails/pull/50492

Thanks for the repro. I’ll look into fixing this tomorrow.

The issue still seems to be present. Running rails (7.1.3.2)

I have a “dashboard” action on Customers controller that displays a bunch of stats for Customer model.

Customer.sales_stats = > runs about 20+ async_count, async_avg, etc on various Customer scopes.

Example

 customer_count = Customer.by_usa_zip_code.async_count
 customer_count.value #=> <ActiveRecord::Promise status=complete>
 #=> returns promise in the view,  but if I call it in  rails console it returns counts as expected. 
 customer_count.value.value 
 # just like above, is what I have to do

I tried using gem "rails", github: "rails/rails", branch: "7-1-stable" to no avail.