-
Notifications
You must be signed in to change notification settings - Fork 328
Description
#write_lobs only serializes attribute before writing to the database when it is ActiveRecord::Type::Serialized. Then value.to_s is written to the database ignoring ActiveRecord type serialization method.
Attributes should always be serialized before writing to the database. I don't see how custom attributes are supposed to be used otherwise.
A workaround for this would be to define #to_s of the custom attribute which does the same as serialization to database, but this is not often undesirable.
I tested with 1.7 as stated at the bottom but I see same logic used in master too.
Steps to reproduce
- have a CLOB column type
- have a field with custom attribute, e.g.
class MyCustomAttribute < ActiveRecord::Type::Text - try to use attribute
my_model.myattribute = "whatever long serialized string ..."
my_model.save!
my_model.myattribute
=> whatever deserialized object as expected
my_model.reload
my_model.myattribute
Expected behavior
=> whatever deserialized object as expected
Basically everything works as if ActiveRecord::Type::Text has been used.
Actual behavior
=> "#<MyDeserializedClass:0x0000000010967bd8>tring ..."
System configuration
Rails version: 5.0.7.2
Oracle enhanced adapter version: activerecord-oracle_enhanced-adapter (1.7.11)
Ruby version: ruby 2.5.9p229bu
Oracle Database version: oracle:19.3.0