Fix exception in attr reader without selecting encrypted column#299
Open
domcleal wants to merge 1 commit intoattr-encrypted:masterfrom
Open
Fix exception in attr reader without selecting encrypted column#299domcleal wants to merge 1 commit intoattr-encrypted:masterfrom
domcleal wants to merge 1 commit intoattr-encrypted:masterfrom
Conversation
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.
65ec470 to
707e6f1
Compare
|
Would be nice to get it merged, I'm also having the same problem 👍 |
|
I'm also facing same issue. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using AR's .select to retrieve a subset of columns for a model,
calling the encrypted attribute reader results in an exception:
The virtual attribute
emailis defined in the test, but the reader tries toaccess the encrypted column which wasn't selected. This is a problem when
rendering a model
#to_jsonwith the default serialiser, as it tries to readall defined columns.
Allow the reader to return nil in the case when the encrypted attribute
column isn't available.