Skip to content

Commit 5a51610

Browse files
authored
Merge pull request rails#48039 from ghiculescu/ar-encryption-default-proc
Fix `Marshal.dump` on records that use AR Encryption
2 parents bad9aa1 + c363334 commit 5a51610

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

activerecord/lib/active_record/encryption/encryptable_record.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def encrypt_attribute(name, attribute_scheme)
8484

8585
attribute name do |cast_type|
8686
ActiveRecord::Encryption::EncryptedAttributeType.new(scheme: attribute_scheme, cast_type: cast_type,
87-
default: -> { columns_hash[name.to_s]&.default })
87+
default: columns_hash[name.to_s]&.default)
8888
end
8989

9090
preserve_original_encrypted(name) if attribute_scheme.ignore_case?

activerecord/lib/active_record/encryption/encrypted_attribute_type.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ def previous_type?
7676
def decrypt(value)
7777
with_context do
7878
unless value.nil?
79-
default = @default.call if @default
80-
81-
if default && default == value
79+
if @default && @default == value
8280
value
8381
else
8482
encryptor.decrypt(value, **decryption_options)

activerecord/test/cases/encryption/encryptable_record_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ def name
303303
assert_equal "<untitled>", book.name
304304
end
305305

306+
test "can dump and load records that use encryption" do
307+
book = EncryptedBook.create!
308+
assert_equal book, Marshal.load(Marshal.dump(book))
309+
end
310+
306311
private
307312
class FailingKeyProvider
308313
def decryption_key(message) end

0 commit comments

Comments
 (0)