Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lockbox raises MissingAttributeError when encrypted attribute is backed by store_attribute when using select #174

Closed
StanleyAu opened this issue Feb 23, 2023 · 1 comment

Comments

@StanleyAu
Copy link

Take a hypothetical ActiveRecord:

class MyRecord < ApplicationRecord
    store_attribute :store, :secret_ciphertext, :string
    has_encrypted :secret
end

Fetch a record using select to limit columns returned:

record = MyRecord.select(:id).first

Attempt to call .attributes on record

record.attributes

# => ActiveRecord::MissingAttributeError: missing attribute: store

Seems to be due to use of send(encrypted_attribute) in https://github.com/ankane/lockbox/blob/master/lib/lockbox/model.rb#L469
whereas regular attributes come from the instance var @attributes

@ankane
Copy link
Owner

ankane commented Feb 23, 2023

Hey @StanleyAu, I haven't tried the store_attribute gem (and it's not officially supported), but looking at the docs, you'll want to create a store_ciphertext column and use has_encrypted :store.

class MyRecord < ApplicationRecord
  store_attribute :store, :secret, :string
  has_encrypted :store
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants