diff options
author | James Coleman <jtc331@gmail.com> | 2014-05-02 12:32:49 -0400 |
---|---|---|
committer | James Coleman <jtc331@gmail.com> | 2014-05-02 12:39:40 -0400 |
commit | 12ff63b227e7ef01c7e57302c9999151dca157f1 (patch) | |
tree | 529ebbb8ef35930db431ae13cdb488a66c9925f8 /activerecord | |
parent | 504adac36ed2b57616c34a5c1f2b565333cb9533 (diff) | |
download | rails-12ff63b227e7ef01c7e57302c9999151dca157f1.tar.gz rails-12ff63b227e7ef01c7e57302c9999151dca157f1.tar.bz2 rails-12ff63b227e7ef01c7e57302c9999151dca157f1.zip |
Fix exception when logging SQL w/ nil binary value.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/log_subscriber.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/log_subscriber_test.rb | 7 |
3 files changed, 20 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index df73eb4484..0b27aabf63 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,15 @@ +* Log nil binary column values correctly. + + When an object with a binary column is updated with a nil value + in that column, the SQL logger would throw an exception when trying + to log that nil value. This only occurs when updating a record + that already has a non-nil value in that column since an initial nil + value isn't included in the SQL anyway (at least, when dirty checking + is enabled.) The column's new value will now be logged as `<NULL binary data>` + to parallel the existing `<N bytes of binary data>` for non-nil values. + + *James Coleman* + * Stringify all variable keys of mysql connection configuration. When the `sql_mode` variable for mysql adapters is set in the configuration diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index 654ef21b07..17d0c52e47 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -25,7 +25,7 @@ module ActiveRecord if column.binary? # This specifically deals with the PG adapter that casts bytea columns into a Hash. value = value[:value] if value.is_a?(Hash) - value = "<#{value.bytesize} bytes of binary data>" + value = value.nil? ? "<NULL binary data>" : "<#{value.bytesize} bytes of binary data>" end [column.name, value] diff --git a/activerecord/test/cases/log_subscriber_test.rb b/activerecord/test/cases/log_subscriber_test.rb index 97c0350911..a578e81844 100644 --- a/activerecord/test/cases/log_subscriber_test.rb +++ b/activerecord/test/cases/log_subscriber_test.rb @@ -125,5 +125,12 @@ class LogSubscriberTest < ActiveRecord::TestCase wait assert_match(/<16 bytes of binary data>/, @logger.logged(:debug).join) end + + def test_nil_binary_data_is_logged + binary = Binary.create(data: "") + binary.update_attributes(data: nil) + wait + assert_match(/<NULL binary data>/, @logger.logged(:debug).join) + end end end |