Skip to content

Commit

Permalink
Don't Read IO Objects in Attribute Value Marshal
Browse files Browse the repository at this point in the history
Resolves Issue #831

Running the following code exercised the problem, and now works with
this change:

```
dynamodb.put_item(
  table_name: "foo",
  item: {
    id: 1,
    contents: StringIO.new("bar")
  }
)
```

The issue appeared to be that #read was called twice on the StringIO or
IO object, and the second call would fail as String#read does not
exist.
  • Loading branch information
awood45 committed Jun 2, 2015
1 parent be9b131 commit b59e760
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core/dynamodb/attribute_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def format(obj)
end
when String then { s: obj }
when Numeric then { n: obj.to_s }
when StringIO, IO then { b: obj.read }
when StringIO, IO then { b: obj }
when Set then format_set(obj)
when true, false then { bool: obj }
when nil then { null: true }
Expand Down
6 changes: 6 additions & 0 deletions aws-sdk-core/spec/aws/dynamodb/attribute_value_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ module DynamoDB
])
end

it 'converts IO objects to :b (blob)' do
io = StringIO.new('bar')
formatted = value.marshal(foo: io)
expect(formatted[:m]["foo"][:b].read).to eq('bar')
end

it 'converts string sets to :ss (string set)' do
formatted = value.marshal(Set.new(%w(abc mno)))
expect(formatted).to eq(ss: %w(abc mno))
Expand Down

0 comments on commit b59e760

Please sign in to comment.