diff --git a/activerecord/lib/active_record/encryption/extended_deterministic_queries.rb b/activerecord/lib/active_record/encryption/extended_deterministic_queries.rb index 8e4a04a4b66..4ebc4137c4f 100644 --- a/activerecord/lib/active_record/encryption/extended_deterministic_queries.rb +++ b/activerecord/lib/active_record/encryption/extended_deterministic_queries.rb @@ -44,12 +44,12 @@ module ActiveRecord return args if owner.deterministic_encrypted_attributes&.empty? if args.is_a?(Array) && (options = args.first).is_a?(Hash) - options = options.dup + options = options.stringify_keys args[0] = options owner.deterministic_encrypted_attributes&.each do |attribute_name| type = owner.type_for_attribute(attribute_name) - if !type.previous_types.empty? && value = options[attribute_name] + if !type.previous_types.empty? && value = options[attribute_name.to_s] options[attribute_name] = process_encrypted_query_argument(value, check_for_additional_values, type) end end diff --git a/activerecord/test/cases/encryption/extended_deterministic_queries_test.rb b/activerecord/test/cases/encryption/extended_deterministic_queries_test.rb index 1f76ac3b972..fa4873faf55 100644 --- a/activerecord/test/cases/encryption/extended_deterministic_queries_test.rb +++ b/activerecord/test/cases/encryption/extended_deterministic_queries_test.rb @@ -25,6 +25,11 @@ class ActiveRecord::Encryption::ExtendedDeterministicQueriesTest < ActiveRecord: assert EncryptedBookWithDowncaseName.find_by(name: "DUNE") end + test "Works well with string attribute names" do + UnencryptedBook.create! "name" => "Dune" + assert EncryptedBook.find_by("name" => "Dune") + end + test "find_or_create works" do EncryptedBook.find_or_create_by!(name: "Dune") assert EncryptedBook.find_by(name: "Dune")