Fix pg instrumentation raising ArgumentError when params is omitted#6020
Conversation
pg instrumentation makes exec_prepared's params argument mandatory, raising ArgumentError for calls like exec_prepared(statement_name) that work fine with plain pg.
The same mandatory-params arity bug affects exec_params, async_exec_params, sync_exec_params, async_exec_prepared, and sync_exec_prepared, not just exec_prepared, since native pg treats params as optional across all of them.
Forward params via *args instead of a mandatory positional parameter, matching native pg's arity where params defaults to nil/none.
This comment has been minimized.
This comment has been minimized.
BenchmarksBenchmark execution time: 2026-07-10 09:27:35 Comparing candidate commit 91dbb4f in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 48 metrics, 1 unstable metrics.
|
@TonyCTHsu Would you have a link for that so it's easy to see? Also I wonder if any of these methods can take keyword arguments. |
Actually the second shows
|
What does this PR do?
Fixes the
pgintegration's instrumentation wrapper so thatparamsis optional onexec_params,exec_prepared, and theirasync_/sync_variants, matching nativepg's own method signatures.Motivation:
The instrumentation wraps these methods with a mandatory
paramspositional argument, but nativepgtreatsparamsas optional on all of them (e.g.conn.exec_prepared(statement_name)is valid). Once thepgintegration is instrumented, calling any of these methods with only the required arguments raisesArgumentError: wrong number of arguments (given 1, expected 2+), even though the same call succeeds with plainpg.Change log entry
Yes. Fixed an issue where
pginstrumentation raisedArgumentErrorwhen callingexec_params,exec_prepared, or theirasync_/sync_variants without aparamsargument.Additional Notes:
All six affected methods (
exec,exec_params,exec_prepared, and theirasync_/sync_variants) are defined in nativepgas C functions with variadic arity (rb_define_method(..., -1)), meaningpgitself performs argument-count validation internally rather than via a fixed Ruby method signature. This was confirmed empirically: callingconn.exec_params('SELECT 1')andconn.exec_prepared('stmt')(both omittingparams) succeed against plainpg(verified on pg gem 1.5.9), matching the documented signatures at https://rubydoc.info/gems/pg/PG/Connection#exec_prepared-instance_method and https://rubydoc.info/gems/pg/PG/Connection#exec_params-instance_method, which showparamsas optional (defaulting to no bind parameters) for both.How to test the change?
Added regression tests covering calls without
paramsforexec_params,exec_prepared,async_exec_params,async_exec_prepared,sync_exec_params, andsync_exec_preparedinspec/datadog/tracing/contrib/pg/patcher_spec.rb. These tests fail with the reportedArgumentErroragainst the prior code and pass with the fix.