-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle ActionDispatch::Response::RackBody as body #22
Conversation
6590400
to
d8cc3ff
Compare
Whew, I got quite scared when I read the gem is not working for you with Rails 7.1. In our project (also Rails 7.1), it does. We insert the middleware directly in the base controller (a barely-known Rails feature), can you try that out to get closer to the root cause? (You hinted middleware order may play a role.) class MyRailsController
use Idempo, backend: Idempo::ActiveRecordBackend.new, other: options
end |
I am inclined to merge this with a few changes (only relying on |
No big objections, haven't peeked into the insides of Rack here. Is there any way we can add some regression tests around this? |
@julik > only relying on to_ary if we are, in fact, under Rack 3 or greater I'll make a change. |
e77725f
to
aed365d
Compare
449bdc8
to
94d9221
Compare
94d9221
to
c8bbc89
Compare
@julik Did couple of adjustments.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few tweaks still needed. Also maybe a good idea to note around rack_response_body.close
that this will not be applied to Arrays resulting from to_ary
@julik thanks for such a thorough review! I have implemented requested changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. One little optional bit and we're good to go
lib/idempo.rb
Outdated
# In some cases `body` could respond to to_ary. In this case, we don't need to call .close on body afterwards. | ||
# | ||
# @see https://github.com/rack/rack/blob/main/SPEC.rdoc#the-body- | ||
body = body.try(:to_ary) if rack_v3? && body.respond_to?(:to_ary) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: since you already do respond_to?
you don't need try() you can call
to_ary` directly
With our new rails 7.1 project, idempotent requests don't seem to be working. They are not even saved.
As it turns out, Idempo middleware receives an instance of
ActionDispatch::Response::RackBody
as a body. And since it's not Array, we're not saving that body.I'm not sure exactly why another project based on rails 7.0 keeps working. Because rails started returning
ActionDispatch::Response::RackBody
pre 7.0 version. I assume, that this could be due to the way how middleware is being inserted (how deep in a stack).Here is what we do in our
application.rb
:And here is an output of
rails middleware
:But that is just a wild guess.
As a fix, I suggest trying converting body to array — this proved effective in our project.