Skip to content

#write_lobs should always serialize attributes #2200

@akostadinov

Description

@akostadinov

#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

  1. have a CLOB column type
  2. have a field with custom attribute, e.g. class MyCustomAttribute < ActiveRecord::Type::Text
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions