-
Notifications
You must be signed in to change notification settings - Fork 427
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
attr_encrypted seems to break serialized attributes #11
Comments
I've seen the exact same behaviour with a Rails 3/Ruby 1.9.2 app.
Note for those who (would) wonder how attr_encrypted works in a Rails 3 app: I'm using the fork from cgod |
I was running into the same issue before which is why I added the We may be able to add some type of serialization related logic to the |
So, what is the best way to handle serialized encrypted attributes right now for Rails 2.3.11? I've tried changing the ordering of serialize and attr_encrypted, and I have tried adding :marshal => true, but nothing seems to work. |
@warnickr I'd recommend sticking with the Did you remove the call to |
I ended up modifying the gem to support serialized attributes in Rails. It is working for what I need it for and I would be happy to submit my changes. |
That'd be great, thanks! |
Great. I will add some tests and make a pull request. |
Is there any reason to continue using serialize if using attr_encrypted? Wouldn't you just use the :marshal option on attr_encrypted and stop using serialize? (we can certainly update the documentation/README to make this clearer) Thanks! |
As far as anyone knows, does Obviously with |
Hi @troy, The problem still exists in Rails 3.2. The workaround in #46 does fix the problem but obviously that's not what we want long term. PR #22 provides a solution but it doesn't seem to be working for me in a 3.2 application and when I clone the repository a lot of the tests are broken. We'll keep you posted. |
FYI... we have found a potential fix for this (and #46) the ActiveRecord attr_encrypted adapter adds accessor methods before invoking the base attr_encrypted functionality so that it can detect the attributes. Unfortunately, this means that they are defined before the serializers are set up too. We either need to change the way that attributes are detected (ie. not add the accessor methods), or unload the accessor methods when done, so that things like serializers load correctly. fix coming soon... |
- In the ActiveRecord adapter, we want to let ActiveRecord call define_attribute_methods. If we call it, we're calling it too early, which causes the wrong accessor methods to be created. This was the problem that was being encountered with serialize. That problem is documented here 0b8c0f6 - By letting ActiveRecord define accessor methods, things behave as they should. Namely, ActiveRecord checks to see if an attribute already has accessor methods defined before defining them. Using something like serialize, accessors are written, and then ActiveRecord sees this and doesn't define the accessor methods. So the attr_encrypted and serialize accessors work as expected, as well as normal accessors. - We add the column names to the instance_methods_as_symbols array so that attr_encrypted will not define accessor methods for the columns, we let ActiveRecord do this for us, as it should.
Just observed the following behavior:
attr_encrypted
serialize :attribute
below itAfter that, my serialized fields weren't being de-serialized. Accessing the attribute yielded the YAML string instead of the deserialized object (Array in my case).
Moving the
attr_encrypted
call to after theserialize
call seems to have fixed that specific problem. Makes me worry about more hidden issues though.This is on Rails 2.3.2 and Ruby 1.8.7.
The text was updated successfully, but these errors were encountered: