-
Notifications
You must be signed in to change notification settings - Fork 181
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
New ActiveRecord find_by_sql
patch fails to pass &block
argument
#1258
Comments
cc: @mrsimo |
@olepbr if you are available to put together a bug fix PR that would be amazing! otherwise I think we need to revert the changes from the previous PR ASAP cc: @open-telemetry/ruby-contrib-approvers |
`find_by_sql` takes a block as its final argument, which is neither a positional nor a keyword argument, hence we need to pass it explicitly; before this commit, the block was not passed to the `super()` call and hence not executed, thus altering application behavior. Fixes open-telemetry#1258
Thanks for pinging me @arielvalentin ❤️ . It's very close to my EOD, but I'd be happy to work on a patch tomorrow morning. This is broken in Rails 8.0 which was released very recently, and I don't see it in the If we can wait a day to roll forward with this instead of reverting it seems like an easy enough fix? |
EOD here too, but added the patch in #1259. Need to leave now; will sign CLA later. |
`find_by_sql` takes a block as its final argument, which is neither a positional nor a keyword argument, hence we need to pass it explicitly; before this commit, the block was not passed to the `super()` call and hence not executed, thus altering application behavior. Fixes open-telemetry#1258
I wanted to mention that I now see the |
Description of the bug
The new patch for ActiveRecord's
find_by_sql
, added in #1184 and released inopentelemetry-instrumentation-active_record
v0.8.0 alters application behaviour. The PR changed the patch from using argument forwarding (def find_by_sql(...)
) to usingdefine_method
with explicitly passed arguments:opentelemetry-ruby-contrib/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/patches/querying.rb
Lines 20 to 27 in bf6394d
The problem with this approach is that the function signature of
find_by_sql
looks like this:Notice that
find_by_sql
takes&block
as its final argument, which is neither a positional nor a keyword argument. The old argument forwarding approach automatically forwards&block
as well, but the new patch's|*args, **kwargs|
is not equivalent. As a result, the block is not passed to thesuper()
call and hence not executed. I noticed this becauseopentelemetry-instrumentation-active_record
v0.8.0 breaks some specs in a Rails application I work on; downgrading to v0.7.4 makes the specs pass again.I believe just passing
&block
to thedo
block and specifying it in thesuper()
call is all that is needed to resolve this:Monkey-patching the gem with the above diff makes my specs pass, at least.
Share details about your runtime
Operating system details: Debian GNU/Linux trixie (testing)
RUBY_ENGINE: "ruby"
RUBY_VERSION: "3.0.6"
RUBY_DESCRIPTION: "ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-linux]"
Share a simplified reproduction if possible
I'm not familiar enough with OpenTelemetry or ActiveRecord's internals to provide a minimal repro, I'm sorry. I hope the above description and suggested fix help, at least.
All the best,
Ole
The text was updated successfully, but these errors were encountered: