Skip to content

Commit

Permalink
Resolved a regression with DynamoDB and paging with attribute values.
Browse files Browse the repository at this point in the history
Fixes #843
  • Loading branch information
trevorrowe committed Jun 16, 2015
1 parent eca3c15 commit b7b8f25
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Unreleased Changes
------------------

* Issue - Aws::DynamoDB - Resolved an issue with pageable responses where the
paging token values contained attribute values.

See [related GitHub issue #843](https://github.com/aws/aws-sdk-ruby/issues/843)

* Issue - Aws::IAM - Added missing paginator configurations for the newer
IAM attached policy operations.

Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core/pageable_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def next_response(params)
# @return [Hash] Returns the hash of request parameters for the
# next page, merging any given params.
def next_page_params(params)
context.params.merge(@pager.next_tokens(self).merge(params))
context[:original_params].merge(@pager.next_tokens(self).merge(params))
end

# Raised when calling {PageableResponse#next_page} on a pager that
Expand Down
1 change: 1 addition & 0 deletions aws-sdk-core/lib/aws-sdk-core/plugins/response_paging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def pageable_operations(config)
class Handler < Seahorse::Client::Handler

def call(context)
context[:original_params] = context.params
resp = @handler.call(context)
resp.extend(PageableResponse)
resp.pager = context.operation[:pager]
Expand Down
31 changes: 31 additions & 0 deletions aws-sdk-core/spec/aws/dynamodb/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@ module DynamoDB
end

end

describe '#enumerable responses' do

it 'can round trip paging params that contain item attributes' do
client = Client.new(stub_responses: {
query: {
:items=> [
{"indexhash"=>"hash", "id"=>"id-1", "indexrange"=>"range-1"},
{"indexhash"=>"hash", "id"=>"id-2", "indexrange"=>"range-2"},
],
:count=>2,
:scanned_count=>2,
:last_evaluated_key=>{
"indexhash"=>"hash", "id"=>"id-160", "indexrange"=>"range-160"
}
}
})
result = client.query(
table_name: 'table-name',
limit: 2,
index_name: 'indexname',
key_condition_expression: 'indexhash = :value1',
expression_attribute_values: { ':value1' => 'hash'}
)
result2 = result.next_page
expect(result2.context.params[:expression_attribute_values]).to eq(
':value1' => { s:'hash'}
)
end

end
end
end
end
9 changes: 5 additions & 4 deletions aws-sdk-core/spec/aws/pageable_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Aws
def pageable(resp, pager)
resp.extend(PageableResponse)
resp.pager = pager
resp.context[:original_params] = resp.context.params
resp
end

Expand Down Expand Up @@ -177,7 +178,7 @@ def pageable(resp, pager)

it 'raises not implemented error by default' do
data = double('data')
resp = double('resp', data:data, error:nil, context:nil)
resp = Seahorse::Client::Response.new(data:data)
page = pageable(resp, pager)
expect {
page.count
Expand All @@ -186,21 +187,21 @@ def pageable(resp, pager)

it 'passes count from the raises not implemented error by default' do
data = double('data', count: 10)
resp = double('resp', data:data, error:nil, context:nil)
resp = Seahorse::Client::Response.new(data:data)
page = pageable(resp, pager)
expect(page.count).to eq(10)
end

it 'returns false from respond_to when count not present' do
data = double('data')
resp = double('resp', data:data, error:nil, context:nil)
resp = Seahorse::Client::Response.new(data:data)
page = pageable(resp, pager)
expect(page.respond_to?(:count)).to be(false)
end

it 'indicates it responds to count when data#count exists' do
data = double('data', count: 10)
resp = double('resp', data:data, error:nil, context:nil)
resp = Seahorse::Client::Response.new(data:data)
page = pageable(resp, pager)
expect(page.respond_to?(:count))
end
Expand Down

0 comments on commit b7b8f25

Please sign in to comment.