Dynamoid / dynamoid

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

Updating an attribute that is a key of a GSI to `nil` (3.9.0) #679

Closed zak-raw closed 1 year ago

zak-raw commented 1 year ago

Since 3.9.0, An error Aws::DynamoDB::Errors::ValidationException: Invalid attribute value type is raised when trying to update an attribute that is a key of a GSI to nil via save!, update_attributes!, etc. This was possible until 3.8.0.

Also, it seems a configuration store_attribute_with_nil_value: false don't work.

Dynamoid.configure do |config|
  config.store_attribute_with_nil_value = false
end

class Hoge
  include Dynamoid::Document

  field :foo_id

  global_secondary_index(
    hash_key: :foo_id,
    projected_attributes: :all,
  )
end

hoge = Hoge.new(foo_id: 'bar').save!
hoge.foo_id = nil
hoge.save!
# 'Aws::DynamoDB::Errors::ValidationException: Invalid attribute value type' is raised.
nbulaj commented 1 year ago

Just faced the same issue. Not sure if it's AWS or Dynamoid

image

andrykonchin commented 1 year ago

Thank you for the bug report. I fixed the issue in https://github.com/Dynamoid/dynamoid/pull/681. Could you please take a look and check whether it fixes your issue?

Not sure that it makes sense to prepare a patch-level release now because there is already one merged PR with refactoring and new feature (https://github.com/Dynamoid/dynamoid/pull/655).

zak-raw commented 1 year ago

@andrykonchin Thank you for your prompt response. 🙇 I checked the diff and I think the issue is resolved. I will update Gemfile and test our Rails application when 3.9.1 is released.