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
- here is the controller: https://github.com/guillaumebriday/async_count_bug/blob/main/app/controllers/posts_controller.rb#L5-
- here is the view: https://github.com/guillaumebriday/async_count_bug/blob/main/app/views/posts/index.html.erb#L10-L11
ping @fatkodima
Actual behavior
We need to use .value.value to get the actual value instead of .value only as it was before
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
- Use async count in admin dashboard This has basic changes to add async counting. Running `bin/rspec spec/controllers/admin/dashboard_controller_spec.rb` passes in main and should pass here. Related... — committed to mjankowski/mastodon by mjankowski 2 years ago
- Use async count in admin dashboard This has basic changes to add async counting. Running `bin/rspec spec/controllers/admin/dashboard_controller_spec.rb` passes in main and should pass here. Related... — committed to mjankowski/mastodon by mjankowski 2 years ago
- Use async count in admin dashboard This has basic changes to add async counting. Running `bin/rspec spec/controllers/admin/dashboard_controller_spec.rb` passes in main and should pass here. Related... — committed to mjankowski/mastodon by mjankowski 2 years ago
- Use async count in admin dashboard This has basic changes to add async counting. Running `bin/rspec spec/controllers/admin/dashboard_controller_spec.rb` passes in main and should pass here. Related... — committed to mjankowski/mastodon by mjankowski 2 years ago
- Use async count in admin dashboard This has basic changes to add async counting. Running `bin/rspec spec/controllers/admin/dashboard_controller_spec.rb` passes in main and should pass here. Related... — committed to mjankowski/mastodon by mjankowski 2 years ago
- Use async count in admin dashboard This has basic changes to add async counting. Running `bin/rspec spec/controllers/admin/dashboard_controller_spec.rb` passes in main and should pass here. Related... — committed to mjankowski/mastodon by mjankowski 2 years ago
- Use async count in admin dashboard This has basic changes to add async counting. Running `bin/rspec spec/controllers/admin/dashboard_controller_spec.rb` passes in main and should pass here. Related... — committed to mjankowski/mastodon by mjankowski 2 years ago
- Use async count in admin dashboard This has basic changes to add async counting. Running `bin/rspec spec/controllers/admin/dashboard_controller_spec.rb` passes in main and should pass here. Related... — committed to mjankowski/mastodon by mjankowski 2 years ago
Use this in the Gemfile:
Yes, that is correct.
I am facing the same problem with :
gem "rails", github: "fatkodima/rails", branch: "fix-caching-async-queries"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…
?
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.wrapmethod’s presence is the relevant part of the fix…7-1-stablebranch does have that method - https://github.com/rails/rails/blob/7-1-stable/activerecord/lib/active_record/future_result.rb#L50-L577.1.3.4tag (and other 7.1.x tags) does not? https://github.com/rails/rails/blob/v7.1.3.4/activerecord/lib/active_record/future_result.rb#L48-L50They 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
I tried using
gem "rails", github: "rails/rails", branch: "7-1-stable"to no avail.