diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 935f0353658b7..1d03c0e921002 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -930,7 +930,7 @@ def _create_record(attribute_names = self.attribute_names) ) returning_columns.zip(returning_values).each do |column, value| - _write_attribute(column, value) if !_read_attribute(column) + _write_attribute(column, type_for_attribute(column).deserialize(value)) if !_read_attribute(column) end if returning_values end diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index 62ac4b54021ea..29cd0b6e7db90 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -63,6 +63,8 @@ def test_fills_auto_populated_columns_on_creation assert_not_nil record.modified_time_without_precision assert_not_nil record.modified_time_function + assert_equal "A", record.binary_default_function + if supports_identity_columns? klass = Class.new(ActiveRecord::Base) do self.table_name = "postgresql_identity_table" diff --git a/activerecord/test/schema/postgresql_specific_schema.rb b/activerecord/test/schema/postgresql_specific_schema.rb index 42d87fbd17f23..53cc9cbd8aa8d 100644 --- a/activerecord/test/schema/postgresql_specific_schema.rb +++ b/activerecord/test/schema/postgresql_specific_schema.rb @@ -41,6 +41,7 @@ t.string :char2, limit: 50, default: "a varchar field" t.text :char3, default: "a text field" t.bigint :bigint_default, default: -> { "0::bigint" } + t.binary :binary_default_function, default: -> { "convert_to('A', 'UTF8')" } t.text :multiline_default, default: "--- [] "