[Misc] Fix an exception during exception logging

This broke after the upgrade to rails 7.1 because of https://github.com/rails/rails/pull/46535
This commit is contained in:
Earlopain 2024-04-11 19:10:57 +02:00
parent f328836895
commit d2d6e83537
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
2 changed files with 20 additions and 1 deletions

View File

@ -21,7 +21,7 @@ class ExceptionLog < ApplicationRecord
if unwrapped_exception.is_a?(ActiveRecord::QueryCanceled)
extra_params[:sql] = {}
extra_params[:sql][:query] = unwrapped_exception&.sql || "[NOT FOUND?]"
extra_params[:sql][:binds] = unwrapped_exception&.binds
extra_params[:sql][:binds] = unwrapped_exception&.binds&.map(&:value_for_database)
end
create!(

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
require "test_helper"
class ExceptionLogTest < ActiveSupport::TestCase
self.use_transactional_tests = false
should "log for query timeout errors with bind parameters" do
e = assert_raises(ActiveRecord::QueryCanceled) do
Post.connection.execute("SET STATEMENT_TIMEOUT = 50")
Post.from("pg_sleep(1), posts").where(description: "bind param").count
end
log = ExceptionLog.add(e, 1, ActionDispatch::TestRequest.new("rack.input" => "abc", "REMOTE_ADDR" => "127.0.0.1"))
assert_equal(["bind param"], log.extra_params["sql"]["binds"])
ensure
Post.connection.execute("SET STATEMENT_TIMEOUT = 3000")
ExceptionLog.destroy_all
end
end