-
Chris Bloom authored
In both Rails 5.2 and Rails 6.1, defining a controller action method named `config` will result in a `SystemStackError: stack level too deep` exception for all requests routed to that controller. This is because `ActiveSupport` defines `ActiveSupport::Configurable#config` which is included into `ActionController::Base` by default, and the new config action overrides it. Any actions in the controller will call `render` which eventually will call `logger` which is a configurable attribute which calls `config` which then calls the new `config` action which calls `render` and so on. `config` is not the only method that will trigger this behavior if redefined in a controller: In Rails 6.1, there are 17 methods that would result in `SystemStackError` if redefined, 9 that would result in `ArgumentError`, and 3 that would result in a `AbstractController::DoubleRenderError`. Most of these methods are obvious that they should be avoided, like `render`, but some, including `config` since it's never something the user would typically call themselves and its buried deep down in some dependencies, are surprising when encountered and the `SystemStackError` that simply points back to the action method isn't very helpful when trying to debug what has happened. This commit updates the ActionController Overview section of the Guide to add a note about the potential for this conflict, but stops short of a full list of reserved methods since it's a.) lengthy, and b.) likely to change as internal APIs are updated. Closes to https://github.com/rails/rails/issues/41323
Chris Bloom authoredIn both Rails 5.2 and Rails 6.1, defining a controller action method named `config` will result in a `SystemStackError: stack level too deep` exception for all requests routed to that controller. This is because `ActiveSupport` defines `ActiveSupport::Configurable#config` which is included into `ActionController::Base` by default, and the new config action overrides it. Any actions in the controller will call `render` which eventually will call `logger` which is a configurable attribute which calls `config` which then calls the new `config` action which calls `render` and so on. `config` is not the only method that will trigger this behavior if redefined in a controller: In Rails 6.1, there are 17 methods that would result in `SystemStackError` if redefined, 9 that would result in `ArgumentError`, and 3 that would result in a `AbstractController::DoubleRenderError`. Most of these methods are obvious that they should be avoided, like `render`, but some, including `config` since it's never something the user would typically call themselves and its buried deep down in some dependencies, are surprising when encountered and the `SystemStackError` that simply points back to the action method isn't very helpful when trying to debug what has happened. This commit updates the ActionController Overview section of the Guide to add a note about the potential for this conflict, but stops short of a full list of reserved methods since it's a.) lengthy, and b.) likely to change as internal APIs are updated. Closes to https://github.com/rails/rails/issues/41323
Loading