Skip to content

Import ActionController::MissingRenderer from Rails#245

Open
zzak wants to merge 1 commit into
heartcombo:mainfrom
zzak:move-MissingRenderer
Open

Import ActionController::MissingRenderer from Rails#245
zzak wants to merge 1 commit into
heartcombo:mainfrom
zzak:move-MissingRenderer

Conversation

@zzak

@zzak zzak commented May 29, 2023

Copy link
Copy Markdown

Happened upon this exception when patching this file in rails/rails#48327, the documentation references a method which was moved to this gem, and nothing else in Rails uses it internally.

I think we can move it here and deprecate it from Rails, which I've started working on in rails/rails#48328

@carlosantoniodasilva

Copy link
Copy Markdown
Member

@zzak I can get this into responders and released, but we'll have to update the Rails side of things a bit apparently... we might also have to detect here if the constant is not already defined or something (suppressing possible warnings), I think?

@zzak

zzak commented Apr 16, 2024

Copy link
Copy Markdown
Author

@carlosantoniodasilva Thanks for the ping, yeah I'm not sure but maybe we can do unless defined??

I have to fix the tests (and probably rebase) upstream too, but I think the right thing to do is do the check on responders side.

@zzak zzak force-pushed the move-MissingRenderer branch from 4179e62 to 80a5470 Compare January 12, 2025 06:18
@zzak zzak force-pushed the move-MissingRenderer branch from 80a5470 to bdf7d11 Compare January 12, 2025 06:27
@zzak

zzak commented Jan 12, 2025

Copy link
Copy Markdown
Author

@carlosantoniodasilva Finally got around to this again, and after fixing the deprecation on Rails side, I think the best path forward is to rename the constant inside this gem.

If someone is using an unpatched version of the responders gem, AND updated to a version of Rails with the deprecation, they will see this warning:

DEPRECATION WARNING: ActionController::MissingRenderer is deprecated and will be removed in Rails 8.2. (called from test_raises_missing_renderer_if_an_api_behavior_with_no_renderer at /home/zzak/code/responders/test/action_controller/respond_with_test.rb:726)
F

Failure:
RespondWithControllerTest#test_raises_missing_renderer_if_an_api_behavior_with_no_renderer [test/action_controller/respond_with_test.rb:726]:
[ActionController::DeprecatedMissingRenderer] exception expected, not
Class: <NameError>
Message: <"uninitialized constant ActionController::Responder::MissingRenderer">
---Backtrace---
/home/zzak/code/responders/lib/action_controller/responder.rb:225:in `api_behavior'
/home/zzak/code/responders/lib/action_controller/responder.rb:207:in `rescue in to_format'
/home/zzak/code/responders/lib/action_controller/responder.rb:198:in `to_format'
/home/zzak/code/responders/lib/action_controller/responder.rb:177:in `respond'
/home/zzak/code/responders/lib/action_controller/responder.rb:170:in `call'
/home/zzak/code/responders/lib/action_controller/respond_with.rb:216:in `respond_with'
/home/zzak/code/responders/test/action_controller/respond_with_test.rb:128:in `index'
/home/zzak/code/rails/actionpack/lib/action_controller/metal/basic_implicit_render.rb:8:in `send_action'
/home/zzak/code/rails/actionpack/lib/abstract_controller/base.rb:234:in `process_action'
/home/zzak/code/rails/actionpack/lib/action_controller/metal/rendering.rb:199:in `process_action'
/home/zzak/code/rails/actionpack/lib/abstract_controller/callbacks.rb:261:in `block in process_action'
/home/zzak/code/rails/activesupport/lib/active_support/callbacks.rb:100:in `run_callbacks'
/home/zzak/code/rails/actionpack/lib/abstract_controller/callbacks.rb:260:in `process_action'
/home/zzak/code/rails/actionpack/lib/action_controller/metal/rescue.rb:27:in `process_action'
/home/zzak/code/rails/actionpack/lib/action_controller/metal/instrumentation.rb:76:in `block in process_action'
/home/zzak/code/rails/activesupport/lib/active_support/notifications.rb:212:in `instrument'
/home/zzak/code/rails/actionpack/lib/action_controller/metal/instrumentation.rb:75:in `process_action'
/home/zzak/code/rails/actionpack/lib/action_controller/metal/params_wrapper.rb:259:in `process_action'
/home/zzak/code/rails/actionpack/lib/abstract_controller/base.rb:167:in `process'
/home/zzak/code/rails/actionview/lib/action_view/rendering.rb:40:in `process'
/home/zzak/code/rails/actionpack/lib/action_controller/metal.rb:252:in `dispatch'
/home/zzak/code/rails/actionpack/lib/action_controller/test_case.rb:639:in `block in process_controller_response'
/home/zzak/code/rails/actionpack/lib/action_controller/test_case.rb:631:in `wrap_execution'
/home/zzak/code/rails/actionpack/lib/action_controller/test_case.rb:639:in `process_controller_response'
/home/zzak/code/rails/actionpack/lib/action_controller/test_case.rb:549:in `process'
/home/zzak/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rails-controller-testing-1.0.5/lib/rails/controller/testing/template_assertions.rb:62:in `process'
/home/zzak/code/rails/actionpack/lib/action_controller/test_case.rb:440:in `get'
/home/zzak/code/responders/test/action_controller/respond_with_test.rb:727:in `block in test_raises_missing_renderer_if_an_api_behavior_with_no_renderer'
---------------


bin/rails test /home/zzak/code/responders/test/action_controller/respond_with_test.rb:724

That was before I renamed it internally, I don't think is a problem, if someone is catching this error manually they will also get the warning.

The solution will be to update the responders gem with this patch and replace the constant if being called directly.

There is a gap however, if someone skips the version of Rails which emits the deprecation warning AND has an unpatched responders gem their code may break -- but that is an acceptable trade-off and people should perform upgrades gradually without skipping.

@carlosantoniodasilva

Copy link
Copy Markdown
Member

@zzak I guess one potential issue is that if they're catching this error in their own code, it might break if we raise a different one on a new responders gem (if they just upgrade responders)

We could maybe inherit from ActionController::MissingRenderer for all existing Rails versions, and just define our own as you have today otherwise?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants