-
Notifications
You must be signed in to change notification settings - Fork 22.2k
Rails 7.1 breaks ActionDispatch Enumerator Handling #49588
Copy link
Copy link
Closed
Labels
Milestone
Description
Steps to reproduce
Use an enumerator to pass data to self.response_body
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "rails", "~> 7.1.0"
end
require "rack/test"
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = __dir__
config.hosts << "example.org"
config.session_store :cookie_store, key: "cookie_store_key"
config.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
get "/" => "test#index"
end
end
class TestController < ActionController::Base
include Rails.application.routes.url_helpers
def index
self.response_body = Enumerator.new do |enumerator|
10.times do |n|
enumerator << n.to_s
end
end
end
end
require "minitest/autorun"
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_returns_success
get "/"
assert last_response.ok?
assert last_response.body === '0123456789'
end
private
def app
Rails.application
end
endExpected behavior
Response should contain 0123456789
Actual behavior
Fails with error (error is from my application, seems that minitest is hiding the error somewhere 😃):
Puma caught this error: undefined method `to_ary' for #<Enumerator: #<Enumerator::Generator:0x0000000136b26588>:each>
Did you mean? to_a (NoMethodError)
/Users/arob/.gem/ruby/3.0.6/gems/actionpack-7.1.0/lib/action_dispatch/http/response.rb:107:in `to_ary'
/Users/arob/.gem/ruby/3.0.6/gems/actionpack-7.1.0/lib/action_dispatch/http/response.rb:509:in `to_ary'
/Users/arob/.gem/ruby/3.0.6/gems/rack-2.2.8/lib/rack/body_proxy.rb:41:in `method_missing'
/Users/arob/.gem/ruby/3.0.6/gems/rack-2.2.8/lib/rack/body_proxy.rb:41:in `method_missing'
/Users/arob/.gem/ruby/3.0.6/gems/rack-2.2.8/lib/rack/body_proxy.rb:41:in `method_missing'
/Users/arob/.gem/ruby/3.0.6/gems/rack-2.2.8/lib/rack/body_proxy.rb:41:in `method_missing'
/Users/arob/.gem/ruby/3.0.6/gems/rack-2.2.8/lib/rack/body_proxy.rb:41:in `method_missing'
/Users/arob/.gem/ruby/3.0.6/gems/rack-2.2.8/lib/rack/body_proxy.rb:41:in `method_missing'
/Users/arob/.gem/ruby/3.0.6/gems/puma-6.4.0/lib/puma/request.rb:183:in `prepare_response'
/Users/arob/.gem/ruby/3.0.6/gems/puma-6.4.0/lib/puma/request.rb:133:in `handle_request'
/Users/arob/.gem/ruby/3.0.6/gems/puma-6.4.0/lib/puma/server.rb:443:in `process_client'
/Users/arob/.gem/ruby/3.0.6/gems/puma-6.4.0/lib/puma/server.rb:241:in `block in run'
/Users/arob/.gem/ruby/3.0.6/gems/puma-6.4.0/lib/puma/thread_pool.rb:155:in `block in spawn_thread'
System configuration
Rails version: 7.1.0 (7.0.8 works fine)
Ruby version: 3.0.6
Reactions are currently unavailable