diff --git a/moto/dynamodb2/responses.py b/moto/dynamodb2/responses.py index 20c45560d..0c2890ddc 100644 --- a/moto/dynamodb2/responses.py +++ b/moto/dynamodb2/responses.py @@ -320,14 +320,14 @@ class DynamoHandler(BaseResponse): er = 'com.amazonaws.dynamodb.v20111205#ResourceNotFoundException' return self.error(er) - limit = self.body.get("Limit") - if limit: - items = items[:limit] - reversed = self.body.get("ScanIndexForward") if reversed is False: items.reverse() + limit = self.body.get("Limit") + if limit: + items = items[:limit] + result = { "Count": len(items), "Items": [item.attrs for item in items], diff --git a/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py b/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py index 282599bad..5700b6848 100644 --- a/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py +++ b/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py @@ -570,6 +570,30 @@ def test_query_with_global_indexes(): list(results).should.have.length_of(0) +@mock_dynamodb2 +def test_reverse_query(): + conn = boto.dynamodb2.layer1.DynamoDBConnection() + + table = Table.create('messages', schema=[ + HashKey('subject'), + RangeKey('created_at', data_type='N') + ]) + + for i in range(10): + table.put_item({ + 'subject': "Hi", + 'created_at': i + }) + + results = table.query_2(subject__eq="Hi", + created_at__lt=6, + limit=4, + reverse=True) + + expected = map(Decimal, [5, 4, 3, 2]) + [r['created_at'] for r in results].should.equal(expected) + + @mock_dynamodb2 def test_lookup(): from decimal import Decimal