aws / aws-sdk-ruby-record

Official repository for the aws-record gem, an abstraction for Amazon DynamoDB.
Apache License 2.0
318 stars 41 forks source link

The '#find' command doesn't properly populate database_attribute_name if symbolized #103

Closed awood45 closed 4 years ago

awood45 commented 4 years ago

To reproduce, consider the following class:

class FindTestTable
  include Aws::Record

  string_attr :hash, hash_key: true, database_attribute_name: :hk
  string_attr :range, range_key: true, database_attribute_name: :rk
end

This class will work for creating new items and saving them, but if you run the following, you'll have a problem:

item = FindTestTable.find(hash: 'validh', range: 'validr')
item.to_h # will have nil values for both keys

This works correctly if you stringify the values, as is documented:

class FindTestTable
  include Aws::Record

  string_attr :hash, hash_key: true, database_attribute_name: 'hk'
  string_attr :range, range_key: true, database_attribute_name: 'rk'
end

I think this should be enhanced to properly read from databases when you use symbols for the database_attribute_name, it was likely an oversight on my part that it didn't to begin with. I also think this is likely a decent first issue for someone looking to get familiar with the deserialization logic.

mullermp commented 4 years ago

Thanks Alex. Will take a look at this when we have bandwidth.