ankane / blind_index

Securely search encrypted database fields
MIT License
645 stars 27 forks source link

Crash on rails7 #55

Closed vdaubry closed 1 year ago

vdaubry commented 1 year ago

Hello,

I am migrating a Rails app from Rails 6.1.6 to Rails 7

Using blind_index 2.3.1 and Rails 7.0.4 I have the following error when inserting in the database :

TypeError: no implicit conversion of Symbol into String
/.rvm/gems/ruby-3.0.4/gems/activesupport-7.0.4/lib/active_support/key_generator.rb:40:in `generate_key'

stack : Ruby 3.0.4 rails 7.0.4 blind_index 2.3.1 kms_encrypted 1.4.0 lockbox 1.1.0

Here is the full stacktrace :

TypeError: no implicit conversion of Symbol into String
/.rvm/gems/ruby-3.0.4/gems/activesupport-7.0.4/lib/active_support/key_generator.rb:40:in `generate_key'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/key_generator.rb:33:in `derive_key_from'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/key.rb:19:in `derive_from'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/derived_secret_key_provider.rb:8:in `block in initialize'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/derived_secret_key_provider.rb:8:in `collect'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/derived_secret_key_provider.rb:8:in `initialize'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/scheme.rb:91:in `new'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/scheme.rb:91:in `build_key_provider'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/scheme.rb:50:in `key_provider'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/encrypted_attribute_type.rb:15:in `key_provider'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/encrypted_attribute_type.rb:128:in `encryption_options'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/encrypted_attribute_type.rb:115:in `block in encrypt'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/scheme.rb:67:in `with_context'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/encrypted_attribute_type.rb:15:in `with_context'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/encrypted_attribute_type.rb:114:in `encrypt'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/encrypted_attribute_type.rb:110:in `serialize_with_current'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/encryption/encrypted_attribute_type.rb:38:in `serialize'
/.rvm/gems/ruby-3.0.4/gems/activemodel-7.0.4/lib/active_model/type/helpers/mutable.rb:8:in `cast'
/.rvm/gems/ruby-3.0.4/gems/activemodel-7.0.4/lib/active_model/attribute.rb:179:in `type_cast'
/.rvm/gems/ruby-3.0.4/gems/activemodel-7.0.4/lib/active_model/attribute.rb:43:in `value'
/.rvm/gems/ruby-3.0.4/gems/activemodel-7.0.4/lib/active_model/attribute_set.rb:46:in `fetch_value'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/attribute_methods/read.rb:38:in `_read_attribute'
/.rvm/gems/ruby-3.0.4/gems/activemodel-7.0.4/lib/active_model/attribute_methods.rb:277:in `firstname'
/.rvm/gems/ruby-3.0.4/gems/blind_index-2.3.1/lib/blind_index/model.rb:76:in `block (3 levels) in blind_index'
/.rvm/gems/ruby-3.0.4/gems/blind_index-2.3.1/lib/blind_index/model.rb:84:in `block (4 levels) in blind_index'
/.rvm/gems/ruby-3.0.4/gems/activemodel-7.0.4/lib/active_model/attribute_assignment.rb:49:in `public_send'
/.rvm/gems/ruby-3.0.4/gems/activemodel-7.0.4/lib/active_model/attribute_assignment.rb:49:in `_assign_attribute'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/attribute_assignment.rb:21:in `block in _assign_attributes'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/attribute_assignment.rb:13:in `each'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/attribute_assignment.rb:13:in `_assign_attributes'
/.rvm/gems/ruby-3.0.4/gems/activemodel-7.0.4/lib/active_model/attribute_assignment.rb:34:in `assign_attributes'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/core.rb:468:in `initialize'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/inheritance.rb:75:in `new'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/inheritance.rb:75:in `new'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/persistence.rb:54:in `create!'
/Documents/Projects/fresqueclimat/fresqueclimat/db/seeds.rb:65:in `block in <main>'
/.rvm/gems/ruby-3.0.4/gems/ros-apartment-2.11.0/lib/apartment/adapters/abstract_adapter.rb:89:in `switch'
/Documents/Projects/fresqueclimat/fresqueclimat/db/seeds.rb:57:in `<main>'
/.rvm/gems/ruby-3.0.4/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load'
/.rvm/gems/ruby-3.0.4/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load'
/.rvm/gems/ruby-3.0.4/gems/railties-7.0.4/lib/rails/engine.rb:557:in `block in load_seed'
/.rvm/gems/ruby-3.0.4/gems/activesupport-7.0.4/lib/active_support/callbacks.rb:118:in `block in run_callbacks'
/.rvm/gems/ruby-3.0.4/gems/activesupport-7.0.4/lib/active_support/execution_wrapper.rb:92:in `wrap'
/.rvm/gems/ruby-3.0.4/gems/railties-7.0.4/lib/rails/engine.rb:626:in `block (2 levels) in <class:Engine>'
/.rvm/gems/ruby-3.0.4/gems/activesupport-7.0.4/lib/active_support/callbacks.rb:127:in `instance_exec'
/.rvm/gems/ruby-3.0.4/gems/activesupport-7.0.4/lib/active_support/callbacks.rb:127:in `block in run_callbacks'
/.rvm/gems/ruby-3.0.4/gems/activesupport-7.0.4/lib/active_support/callbacks.rb:138:in `run_callbacks'
/.rvm/gems/ruby-3.0.4/gems/railties-7.0.4/lib/rails/engine.rb:557:in `load_seed'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/tasks/database_tasks.rb:497:in `load_seed'
/.rvm/gems/ruby-3.0.4/gems/activerecord-7.0.4/lib/active_record/railties/databases.rake:397:in `block (2 levels) in <main>'
/.rvm/gems/ruby-3.0.4/gems/sentry-ruby-5.6.0/lib/sentry/rake.rb:26:in `execute'
/.rvm/gems/ruby-3.0.4/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/.rvm/gems/ruby-3.0.4/bin/ruby_executable_hooks:22:in `eval'
/.rvm/gems/ruby-3.0.4/bin/ruby_executable_hooks:22:in `<main>'

Do you have any idea what can cause this issue ?

ankane commented 1 year ago

Hey @vdaubry, it looks like you're probably using encrypts, which uses Active Record encryption in Rails 7+. Use has_encrypted instead. https://github.com/ankane/lockbox#100

vdaubry commented 1 year ago

Great, thx a lot !