New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamoDB: Unable to put binary data #831

Closed
der-flo opened this Issue May 29, 2015 · 4 comments

Comments

Projects
None yet
3 participants
@der-flo

der-flo commented May 29, 2015

When trying to put binary data to DynamoDB, I get an exception regarding the usage of an IO (eg. StringIO) type. I'm using the actual gem (2.0.47).

Simple example to reproduce:

require 'aws-sdk'
client = Aws::DynamoDB::Client.new(region: 'eu-west-1')

item = {
  'id' => 'bar',
  'foo' => StringIO.new('baz')
}
client.put_item(table_name: 'foobar', item: item)

Exception and backtrace:

[...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:54:in `format': undefined method `read' for "baz":String (NoMethodError)
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:24:in `block in structure'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:20:in `each'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:20:in `with_object'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:20:in `structure'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:50:in `format'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:41:in `block in map'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:40:in `each'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:40:in `with_object'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:40:in `map'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:52:in `format'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:24:in `block in structure'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:20:in `each'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:20:in `with_object'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:20:in `structure'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:50:in `format'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/builder.rb:11:in `to_json'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/rpc_body_handler.rb:20:in `build_json'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/rpc_body_handler.rb:8:in `call'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/json/rpc_headers_handler.rb:10:in `call'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/plugins/user_agent.rb:12:in `call'
from [...]/aws-sdk-core-2.0.47/lib/seahorse/client/plugins/restful_bindings.rb:13:in `call'
from [...]/aws-sdk-core-2.0.47/lib/seahorse/client/plugins/endpoint.rb:31:in `call'
from [...]/aws-sdk-core-2.0.47/lib/seahorse/client/plugins/param_validation.rb:22:in `call'
from [...]/aws-sdk-core-2.0.47/lib/seahorse/client/plugins/raise_response_errors.rb:14:in `call'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb:112:in `call'
from [...]/aws-sdk-core-2.0.47/lib/seahorse/client/plugins/param_conversion.rb:22:in `call'
from [...]/aws-sdk-core-2.0.47/lib/aws-sdk-core/plugins/response_paging.rb:10:in `call'
from [...]/aws-sdk-core-2.0.47/lib/seahorse/client/plugins/response_target.rb:18:in `call'
from [...]/aws-sdk-core-2.0.47/lib/seahorse/client/request.rb:70:in `send_request'
from [...]/aws-sdk-core-2.0.47/lib/seahorse/client/base.rb:216:in `block (2 levels) in define_operation_methods'
@awood45

This comment has been minimized.

Show comment
Hide comment
@awood45

awood45 Jun 2, 2015

Member

Thanks for this, I was able to reproduce and I'm taking a look.

Member

awood45 commented Jun 2, 2015

Thanks for this, I was able to reproduce and I'm taking a look.

@awood45 awood45 self-assigned this Jun 2, 2015

@awood45

This comment has been minimized.

Show comment
Hide comment
@awood45

awood45 Jun 2, 2015

Member

I have a possible fix written which passes in your case, but there are a few other cases I want to check in review. Will push up my changes to a branch and PR.

Member

awood45 commented Jun 2, 2015

I have a possible fix written which passes in your case, but there are a few other cases I want to check in review. Will push up my changes to a branch and PR.

awood45 added a commit that referenced this issue Jun 2, 2015

Don't Read IO Objects in Attribute Value Marshal
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.
@trevorrowe

This comment has been minimized.

Show comment
Hide comment
@trevorrowe

trevorrowe Jun 3, 2015

Member

Closed by #832

Member

trevorrowe commented Jun 3, 2015

Closed by #832

@trevorrowe trevorrowe closed this Jun 3, 2015

@der-flo

This comment has been minimized.

Show comment
Hide comment
@der-flo

der-flo Jun 8, 2015

Thanks for version 2.0.48!

der-flo commented Jun 8, 2015

Thanks for version 2.0.48!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment