提交 7922ccb2 编写于 作者: R Rafael Mendonça França

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
* 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.
......
......@@ -25,7 +25,7 @@ def render_bind(column, value)
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]
......
......@@ -125,5 +125,12 @@ def test_binary_data_is_not_logged
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册