From 76856aadc757488418a59cd815fd53fe4e1790db Mon Sep 17 00:00:00 2001 From: Jeff Gregory Date: Sun, 23 Feb 2014 03:11:54 -0800 Subject: [PATCH] Query sort keying on index values and not index hashes which was causing unexpected ording results --- moto/dynamodb2/models.py | 14 ++++++++++++++ moto/dynamodb2/responses.py | 5 ++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/moto/dynamodb2/models.py b/moto/dynamodb2/models.py index 9c045f447..3a330ef17 100644 --- a/moto/dynamodb2/models.py +++ b/moto/dynamodb2/models.py @@ -42,6 +42,18 @@ class DynamoType(object): self.value == other.value ) + def __lt__(self, other): + return self.value < other.value + + def __le__(self, other): + return self.value <= other.value + + def __gt__(self, other): + return self.value > other.value + + def __ge__(self, other): + return self.value >= other.value + def __repr__(self): return "DynamoType: {0}".format(self.to_json()) @@ -196,6 +208,8 @@ class Table(object): else: # If we're not filtering on range key, return all values results = possible_results + + results.sort(key=lambda item: item.range_key) return results, last_page def all_items(self): diff --git a/moto/dynamodb2/responses.py b/moto/dynamodb2/responses.py index 152912db4..9c960ef48 100644 --- a/moto/dynamodb2/responses.py +++ b/moto/dynamodb2/responses.py @@ -238,12 +238,11 @@ class DynamoHandler(BaseResponse): if items is None: er = 'com.amazonaws.dynamodb.v20111205#ResourceNotFoundException' return self.error(er) - - items.sort(key=lambda item: item.range_key) + limit = self.body.get("Limit") if limit: items = items[:limit] - + result = { "Count": len(items), "Items": [item.attrs for item in items],