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

Select query adds attr_encrypted attribute in result even if not requested #365

Open
adelatuduce opened this issue Mar 18, 2020 · 2 comments

Comments

@adelatuduce
Copy link

adelatuduce commented Mar 18, 2020

Hello,

I am struggling with an issue with a Rails 5.2.4.1 app.
Configuration is the following:

  • Ruby 2.6.5
  • Rails 5.2.4.1
  • attr_encrypted 3.1.0

I have a model called Chicken that has 2 attributes: name - which is attr_encrypted and number - which is a normal integer field. Whenever I perform queries to retrieve any other fields except the attr_encrypted one, that still gets attached to the result and it's alway nil:

Chicken.select(:number) => #<ActiveRecord::Relation [#<Chicken id: nil, number: nil, name: nil>]>

Please keep in mind that this is just a test application and the queries that I am trying to execute on the actual app where I have encountered this initially, are more complex.

Is there a way to prevent attr_encrypted from attaching encrypted fields to queries results? Since the current results mean that I have to re-write all the existing queries in the app or add a filter for these types of fields somehow

@adelatuduce adelatuduce changed the title Select query add attr_encrypted attribute in result even if not requested Select query adds attr_encrypted attribute in result even if not requested Mar 18, 2020
@bijalhopkins
Copy link

I am having a similar issue! Any help would be appreciated 🙏

@Qwertie-
Copy link

Qwertie- commented Feb 12, 2021

I have no idea how safe or recommended this is but you can remove the field with this in your model

  def attributes
    super.except('field_name')
  end

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

No branches or pull requests

3 participants