Skip to content

Commit

Permalink
Fix for query method in Dynamo (hedyorg#663)
Browse files Browse the repository at this point in the history
* Fix for query method in Dynamo.

* Use serializer.
  • Loading branch information
fpereiro authored Aug 23, 2021
1 parent 7b2809c commit f739afd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions e2e_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ def suite (username):
['unshare program', 'post', '/programs/share', {}, lambda state: {'id': state ['program'] ['id'], 'public': False}, 200],
['delete program', 'get', lambda state: '/programs/delete/' + state ['program'] ['id'], {}, {}, 302],
['retrieve programs after deleting saved program', 'get', '/programs_list', {}, {}, 200, retrieveProgramsBefore],
['create program before destroying account', 'post', '/programs', {}, {'code': 'print Hello world', 'name': 'Program 1', 'level': 1}, 200],
['destroy account', 'post', '/auth/destroy', {}, {}, 200],
['get programs without being logged in', 'get', '/programs', {}, {}, 302],
# Auth: profile (programming experience)
Expand Down
8 changes: 6 additions & 2 deletions website/dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,13 @@ def get_item(self, table_name, key):
return self._decode(result.get('Item', None))

def query(self, table_name, key, reverse=False):
assert len(key.keys ()) == 1
key_field = list (key.keys ()) [0]
key_value = key [key_field]
result = self.db.query(
TableName=self.db_prefix + '-' + table_name,
Key = self._encode(key),
KeyConditionExpression = key_field + ' = :value',
ExpressionAttributeValues = {':value': self.SERIALIZER.serialize (key_value)},
ScanIndexForward = not reverse)
return list(map(self._decode, result.get('Items', [])))

Expand Down Expand Up @@ -460,4 +464,4 @@ def decode_object(obj):
"""The decoding for the encoding above."""
if obj.get('$type') == 'set':
return set(obj['elements'])
return obj
return obj

0 comments on commit f739afd

Please sign in to comment.