Commits

Jean-Tiare Le Bigot committed 65f2522

fix #9; When QUERY hash_key is not found, return empty result set instead of prpagating a KeyError

Comments (0)

Files changed (2)

ddbmock/database/table.py

         if start and start['HashKeyElement'] != hash_key:
             raise ValidationException("'HashKeyElement' element of 'ExclusiveStartKey' must be the same as the hash_key. Expected {}, got {}".format(hash_key, start['HashKeyElement']))
 
-        data = self.store[hash_value, None]
+        try:
+            data = self.store[hash_value, None]
+        except KeyError:
+            # fix #9: return empty result set if first key does not exist
+            return Results(results, size, lek, -1)
 
         keys = sorted(data.keys())
 

tests/functional/pyramid/test_query.py

         }
 
         # Protocol check
-        res = self.app.post_json('/', request, HEADERS, status=400)
+        res = self.app.post_json('/', request, HEADERS, status=200)
         self.assertEqual(expected, json.loads(res.body))
         self.assertEqual('application/x-amz-json-1.0; charset=UTF-8', res.headers['Content-Type'])