Commit 65ec470
committed
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.1 parent 55839af commit 65ec470
File tree
3 files changed
+32
-3
lines changed- lib
- attr_encrypted/adapters
- test
3 files changed
+32
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
| 165 | + | |
167 | 166 | | |
168 | 167 | | |
169 | 168 | | |
| |||
395 | 394 | | |
396 | 395 | | |
397 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
398 | 408 | | |
399 | 409 | | |
400 | 410 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
130 | 131 | | |
131 | 132 | | |
132 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
133 | 147 | | |
134 | 148 | | |
135 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
338 | 343 | | |
0 commit comments