oracle-enhanced icon indicating copy to clipboard operation
oracle-enhanced copied to clipboard

raw type should be able to deserialize

Open akostadinov opened this issue 3 years ago • 4 comments

ActiveRecord expects types to properly deserialize any values that have been serialized. Right now (Rails 7.1) by every object save the attributes are reset by serialize/deserialize cycle.

see ActiveModel::ActiveModel#forget_attribute_assignments

It might be inefficient but other parts of ActiveRecord and ActiveModel attributes also rely on serialize and deserialize being reversible. At least I saw that #changed_in_place? expects this to be true in some types like Serialized. So it is rather complicated to change Rails to prevent that.

And also it makes intuitive sense that if our class has #serialize and #deserialize methods, that they reverse each other.

So to avoid confusing errors now and going forward, I believe we need this change.

This is more of a hack but I'm not sure of a better way to fix. Provided that we can use #write_lobs for such inserts, then I don't know why we should serialize and insert with the insert statement thus need the #serialize? Related to #2226

I feel there should be a better fix but I'm confused with the whole idea around lob writing.

akostadinov avatar Feb 28 '22 23:02 akostadinov

Related to https://github.com/rails/rails/issues/44317

yahonda avatar Mar 01 '22 10:03 yahonda

Basically if we always use #write_lobs perhaps we don't need to have a #serialize method and thus no fixing would be needed.

And if we believe that #write_lobs is necessary is some use cases, then this or another workaround would be needed. Or Rails to stop updating the attribute value unnecessarily.

akostadinov avatar Mar 01 '22 20:03 akostadinov

@yahonda , I updated implementation and description of this PR. But now all tests fail for some issue with database_version that I don't think I have anything to do with that. Would you advise?

akostadinov avatar Nov 18 '22 18:11 akostadinov

bump

akostadinov avatar Dec 21 '22 14:12 akostadinov