rsim / oracle-enhanced

Oracle enhaced adapter for ActiveRecord
MIT License
547 stars 308 forks source link

all attributes serialized before writing #2203

Closed akostadinov closed 2 years ago

akostadinov commented 3 years ago

As described in #2200, presently only ActiveRecord::Type::Serialized attributes are serialized before being written to database by #write_lobs.

It was introduced with 75ed13e6a7c42024ff4d57642a1a06f2bdfedc99

Any other attributes are just converted to string by value.to_s.

My understanding is that all attributes should go through standard serialization regardless their type. Especially any custom attributes. Otherwise instead of writing whatever serialized form of attribute is, database record would become "#<MyCustomAttributeType:0x000000000bdb6590>\",\"whaever garbage... or some other string representation that was not intended to end up inside the database.

With this update all attributes get serilized in the standard way.

/fixes #2200

yahonda commented 2 years ago

Thanks for opening a pull request. Would you add some specs to make sure your change will not be broken in the future? Thank you.

akostadinov commented 2 years ago

@yahonda , good idea, I added. If you can, please take a look. Thank you!

P.S. while writing the tests I noticed something that I didn't expect. I don't know if it is a bug or expected behavior. I will appreciate feedback on it as well - #2226

yahonda commented 2 years ago

Just a note: if klass.attribute_types[col.name].is_a? ActiveRecord::Type::Serialized has been added via https://github.com/rsim/oracle-enhanced/pull/878