Dynamoid / dynamoid

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

Case where updating array/map fields does not work #738

Closed yoshizaki-aill closed 6 months ago

yoshizaki-aill commented 6 months ago

I'm trying to upgrade Dynamoid 3.8.0 to 3.10.0. Then, there was a case where the array field could not be updated. (Also, the map type is the same.)

Field definition:

field :items, :array, { default: [] }

The following case cannot be saved. This looks confusing.

rec.items << 'foo'
rec.save!
pp rec.items
# ["foo"]
# This looks like it was saved.
pp rec.reload.items
# []
# But it's not actually persisted.

It works if I replace the whole (duplicated) array. However, this can be inconvenient for coding.

rec.items = ['foo']
rec.save!
pp rec.reload.items
# ["foo"]

new_arr = rec.items.dup
new_arr << 'bar'
rec.items = new_arr
rec.save!
pp rec.reload.items
# ["foo", "bar"]
FinnIckler commented 6 months ago

Maybe related to https://github.com/Dynamoid/dynamoid/issues/666 ?

andrykonchin commented 6 months ago

Yes, it seems a symptom of the same issue. Mutated collection/custom type isn't detected as a field change at persisting.

yoshizaki-aill commented 6 months ago

Sorry for creating a duplicate issue. I understood that this is an issue due to a differential update. I certainly think this is a difficult problem. The affected parts of our source code have been fixed, so there is no problem.

Thank you.