Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ignore binds payload with nil column in AR log subscriber
Some tests were raising the following error:

    Could not log "sql.active_record" event. NoMethodError: undefined method
    `type' for nil:NilClass`

Due to the way binds were being logged, the column info was considered
always present, but that is not true for some of the tests listed in the
issue.

Closes #8806.

Conflicts:

	activerecord/lib/active_record/log_subscriber.rb
	activerecord/test/cases/log_subscriber_test.rb

Conflict resolution:
- Revert ruby 1.9 style hash to support ruby 1.8
- Do not include 8f59ffc into 3-2-stable
  • Loading branch information
yahonda committed Jan 8, 2013
1 parent 48810a5 commit 3d1a879
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
6 changes: 5 additions & 1 deletion activerecord/lib/active_record/log_subscriber.rb
Expand Up @@ -32,7 +32,11 @@ def sql(event)

unless (payload[:binds] || []).empty?
binds = " " + payload[:binds].map { |col,v|
[col.name, v]
if col
[col.name, v]
else
[nil, v]
end
}.inspect
end

Expand Down
34 changes: 22 additions & 12 deletions activerecord/test/cases/log_subscriber_test.rb
Expand Up @@ -7,6 +7,19 @@ class LogSubscriberTest < ActiveRecord::TestCase
include ActiveSupport::LogSubscriber::TestHelper
include ActiveSupport::BufferedLogger::Severity

class TestDebugLogSubscriber < ActiveRecord::LogSubscriber
attr_reader :debugs

def initialize
@debugs = []
super
end

def debug message
@debugs << message
end
end

fixtures :posts

def setup
Expand All @@ -32,18 +45,7 @@ def set_logger(logger)
def test_schema_statements_are_ignored
event = Struct.new(:duration, :payload)

logger = Class.new(ActiveRecord::LogSubscriber) {
attr_accessor :debugs

def initialize
@debugs = []
super
end

def debug message
@debugs << message
end
}.new
logger = TestDebugLogSubscriber.new
assert_equal 0, logger.debugs.length

logger.sql(event.new(0, { :sql => 'hi mom!' }))
Expand All @@ -56,6 +58,14 @@ def debug message
assert_equal 2, logger.debugs.length
end

def test_ignore_binds_payload_with_nil_column
event = Struct.new(:duration, :payload)

logger = TestDebugLogSubscriber.new
logger.sql(event.new(0, :sql => 'hi mom!', :binds => [[nil, 1]]))
assert_equal 1, logger.debugs.length
end

def test_basic_query_logging
Developer.all
wait
Expand Down

0 comments on commit 3d1a879

Please sign in to comment.