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

each_instance does not respect ActiveRecord serialize? #29

Closed
indigoviolet opened this issue Dec 21, 2016 · 4 comments
Closed

each_instance does not respect ActiveRecord serialize? #29

indigoviolet opened this issue Dec 21, 2016 · 4 comments

Comments

@indigoviolet
Copy link

I can pull together a more descriptive example if it's useful, but I have a JSON type in the db where I store arrays of stringified integers. I use serialize to serialize arrays of integers to arrays of strings upon save, and to deserialize back into arrays of integers upon load from the db. each_instance doesn't appear to do this; a standard ActiveRecord load does.

http://api.rubyonrails.org/classes/ActiveRecord/AttributeMethods/Serialization/ClassMethods.html

@afair
Copy link
Owner

afair commented Dec 21, 2016

Hello! This is unexpected. There is no behavior in this gem to deal with serialized attributes; that should be handled by ActiveRecord. This method passes each data tuple to ActiveRecord::Base.instantiate() which should be responsible serializing/deserializing.

What versions of Rails/ActiveRecord, Ruby, "pg" and "postgresql_cursor" gems are you running, and in what environment? Can you create a test app with only this model and postgresql_cursor to show the problem?

@indigoviolet
Copy link
Author

Sure, I'll try and do that. I'm using Rails 4.2, most recent postgresql_cursor.

Some quick digging reveals that if you don't pass @column_types to :instantiate at https://github.com/afair/postgresql_cursor/blob/master/lib/postgresql_cursor/cursor.rb#L104, the deserialization works right, but if you do pass it, we don't deserialize correctly.

@pedro-brentan
Copy link

It's been almost 3 years since the issue was opened and more than a year that the fix is ready, why you don't apply it?

@afair
Copy link
Owner

afair commented Sep 27, 2019

Hasn't it? Above PR was merged 18 months ago.

@afair afair closed this as completed Sep 27, 2019
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