1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #14946 from jcoleman/fix-null-binary-column-logging-exception

Fix exception when logging SQL w/ nil binary value.

Conflicts:
	activerecord/CHANGELOG.md
This commit is contained in:
Rafael Mendonça França 2014-05-04 18:20:51 -03:00
commit 7922ccb261
3 changed files with 20 additions and 1 deletions

View file

@ -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*
* Rails will now pass a custom validation context through to autosave associations
in order to validate child associations with the same context.

View file

@ -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]

View file

@ -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