forked from e621ng/e621ng
[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:
parent
f328836895
commit
d2d6e83537
@ -21,7 +21,7 @@ class ExceptionLog < ApplicationRecord
|
|||||||
if unwrapped_exception.is_a?(ActiveRecord::QueryCanceled)
|
if unwrapped_exception.is_a?(ActiveRecord::QueryCanceled)
|
||||||
extra_params[:sql] = {}
|
extra_params[:sql] = {}
|
||||||
extra_params[:sql][:query] = unwrapped_exception&.sql || "[NOT FOUND?]"
|
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
|
end
|
||||||
|
|
||||||
create!(
|
create!(
|
||||||
|
19
test/unit/exception_log_test.rb
Normal file
19
test/unit/exception_log_test.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user