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

Error while selecting specific non encrypted fields #81

Closed
komalkamble opened this issue Sep 18, 2014 · 8 comments · Fixed by #84
Closed

Error while selecting specific non encrypted fields #81

komalkamble opened this issue Sep 18, 2014 · 8 comments · Fixed by #84

Comments

@komalkamble
Copy link

I am encrypting some of the columns of table in my rails app. In model i specify the fields of table to be encryptes. All the encryption and decryption is working fine but in case where i am fetching only specific non encrypted fields like id and name. its throwing an exception like ActiveModel::MissingAttributeError - missing attribute.
stacktrace is as follows:

activemodel (4.0.9) lib/active_model/attribute_methods.rb:481:in `missing_attribute'
  activerecord (4.0.9) lib/active_record/attribute_methods/read.rb:59:in `block in __temp__26c6f6f646f57627f65707'
  activerecord (4.0.9) lib/active_record/attribute_methods/read.rb:95:in `block (2 levels) in read_attribute'
  activerecord (4.0.9) lib/active_record/attribute_methods/read.rb:94:in `block in read_attribute'
  activerecord (4.0.9) lib/active_record/attribute_methods/read.rb:84:in `read_attribute'
  activerecord (4.0.9) lib/active_record/attribute_methods/read.rb:59:in `__temp__26c6f6f646f57627f65707'
  crypt_keeper (0.18.2) lib/crypt_keeper/model.rb:30:in `block in force_encodings_on_fields'
  crypt_keeper (0.18.2) lib/crypt_keeper/model.rb:29:in `force_encodings_on_fields'
  activesupport (4.0.9) lib/active_support/callbacks.rb:375:in `_run__1730928489337275095__find__callbacks'
  activesupport (4.0.9) lib/active_support/callbacks.rb:80:in `run_callbacks'
  activerecord (4.0.9) lib/active_record/core.rb:210:in `init_with'
  activerecord (4.0.9) lib/active_record/persistence.rb:52:in `instantiate'
  activerecord (4.0.9) lib/active_record/querying.rb:45:in `block in find_by_sql'
  activerecord (4.0.9) lib/active_record/result.rb:21:in `block in each'
  activerecord (4.0.9) lib/active_record/result.rb:21:in `each'
  activerecord (4.0.9) lib/active_record/querying.rb:45:in `find_by_sql'
  activerecord (4.0.9) lib/active_record/relation.rb:587:in `exec_queries'
  activerecord (4.0.9) lib/active_record/relation.rb:471:in `load'
  activerecord (4.0.9) lib/active_record/relation.rb:220:in `to_a'
  activerecord (4.0.9) lib/active_record/relation/delegation.rb:12:in `each'

Thanks in advance.
Komal

@jmazzi
Copy link
Owner

jmazzi commented Sep 23, 2014

Can you show me the crypt_keeper line in your model (without the password or salt)? Can you also provide the ActiveRecord query you used?

@komalkamble
Copy link
Author

Hello Justin,

Here is requested info
-crypt_keeper line in model
crypt_keeper :blood_group,:weight,:exercise, :encryptor => :aes_new,
:encoding => 'UTF-8'

-ActiveRecord query

@persons = Person.where("lower(fullname) like ? ",
"%#{params[:term].downcase}%").select("fullname AS name", "id")

Thanks,

On Tue, Sep 23, 2014 at 8:36 PM, Justin Mazzi notifications@github.com
wrote:

Can you show me the crypt_keeper line in your model (without the password
or salt)? Can you also provide the ActiveRecord query you used?


Reply to this email directly or view it on GitHub
#81 (comment).

@edulan
Copy link

edulan commented Oct 9, 2014

Hi,

I think the issue is related to #force_encodings_on_fields method. This method iterates over defined encrypted fields, and uses String#force_encoding method to do the encoding conversion. But when selecting a model attributes subset in a query, some attributes may not be present in the model attributes hash, causing the missing_attribute error.

I would submit a pull request with the fix as soon as I can dedicate my time to it.

Cheers.

@jmazzi
Copy link
Owner

jmazzi commented Oct 17, 2014

@komalkamble can you try using the bugfix/missing_attribute branch?

@jmazzi
Copy link
Owner

jmazzi commented Oct 20, 2014

@komalkamble @edulan the fixed version has been releases as 0.18.3.

@edulan
Copy link

edulan commented Oct 20, 2014

@jmazzi thanks!

@komalkamble
Copy link
Author

I am apologies for late response.
@jmazzi @edulan thank you very much. It's working fine.
Thanks!!!

On Mon, Oct 20, 2014 at 10:43 PM, Eduardo Lanchares <
notifications@github.com> wrote:

@jmazzi https://github.com/jmazzi thanks!


Reply to this email directly or view it on GitHub
#81 (comment).

@jmazzi
Copy link
Owner

jmazzi commented Oct 21, 2014

@komalkamble @edulan no problem!

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

Successfully merging a pull request may close this issue.

3 participants