Dynamoid / dynamoid

Ruby ORM for Amazon's DynamoDB.
MIT License
579 stars 195 forks source link

Not Functioning Correctly on Partial Updates of Serialized Fields #749

Open fukata opened 4 months ago

fukata commented 4 months ago

It seems that changing the value of the serialized field called "options" does not set "changed?" to true. It works correctly when the entire "options" field is modified.

Is this the expected behavior?

Reproduction

Dynamoid: v3.9.0 Ruby: 3.3.0

Sample Test

    context 'serialized field' do
      let(:model) do
        new_class do
          field :options, :serialized
        end
      end

      it 'returns true if serialized field has unsaved changes' do
        obj = model.new(options: {})
        expect(obj.changed?).to eq true

        obj = model.create(options: {})
        obj.options['name'] = 'Alex'
        expect(obj.changed?).to eq true
      end

      it 'returns true if serialized field has unsaved changes other object ' do
        obj = model.new(options: {})
        expect(obj.changed?).to eq true

        obj = model.create(options: {})
        obj.options = {'name' => 'Alex'}
        expect(obj.changed?).to eq true
      end
    end
andrykonchin commented 4 months ago

Thank you for reporting the issue. It's definitely a bug and a similar issue with custom types was reported in #666.