-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix exception in attr reader without selecting encrypted column
When using AR's .select to retrieve a subset of columns for a model, calling the encrypted attribute reader results in an exception: ActiveModel::MissingAttributeError: missing attribute: encrypted_street gems/activerecord-5.1.5/lib/active_record/attribute_methods/read.rb:71:in `block in _read_attribute' gems/activerecord-5.1.5/lib/active_record/attribute_set.rb:45:in `block in fetch_value' gems/activerecord-5.1.5/lib/active_record/attribute.rb:219:in `value' gems/activerecord-5.1.5/lib/active_record/attribute_set.rb:45:in `fetch_value' gems/activerecord-5.1.5/lib/active_record/attribute_methods/read.rb:71:in `_read_attribute' gems/activerecord-5.1.5/lib/active_record/attribute_methods/read.rb:36:in `__temp__56e636279707475646f5374727565647' lib/attr_encrypted.rb:161:in `block (2 levels) in attr_encrypted' The virtual attribute `email` is defined in the test, but the reader tries to access the encrypted column which wasn't selected. This is a problem when rendering a model `#to_json` with the default serialiser, as it tries to read all defined columns. Allow the reader to return nil in the case when the encrypted attribute column isn't available.
- Loading branch information
Showing
3 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters