lib/lockbox/model.rb in lockbox-0.4.2 vs lib/lockbox/model.rb in lockbox-0.4.3
- old
+ new
@@ -85,10 +85,13 @@
def attributes
# load attributes
# essentially a no-op if already loaded
# an exception is thrown if decryption fails
self.class.lockbox_attributes.each do |_, lockbox_attribute|
- send(lockbox_attribute[:attribute])
+ # it is possible that the encrypted attribute is not loaded, eg.
+ # if the record was fetched partially (`User.select(:id).first`).
+ # accessing a not loaded attribute raises an `ActiveModel::MissingAttributeError`.
+ send(lockbox_attribute[:attribute]) if has_attribute?(lockbox_attribute[:encrypted_attribute])
end
super
end
# needed for in-place modifications