dynamodb2 items are copied when using ProjectionExpression to avoid mutating originals
This commit is contained in:
parent
bca97b3772
commit
06492026c3
@ -1,5 +1,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import decimal
|
import decimal
|
||||||
import json
|
import json
|
||||||
@ -492,7 +493,7 @@ class Table(BaseModel):
|
|||||||
|
|
||||||
if projection_expression:
|
if projection_expression:
|
||||||
expressions = [x.strip() for x in projection_expression.split(',')]
|
expressions = [x.strip() for x in projection_expression.split(',')]
|
||||||
for result in possible_results:
|
for result in copy.deepcopy(possible_results):
|
||||||
for attr in list(result.attrs):
|
for attr in list(result.attrs):
|
||||||
if attr not in expressions:
|
if attr not in expressions:
|
||||||
result.attrs.pop(attr)
|
result.attrs.pop(attr)
|
||||||
|
@ -371,6 +371,15 @@ def test_basic_projection_expressions():
|
|||||||
assert 'body' in results['Items'][1]
|
assert 'body' in results['Items'][1]
|
||||||
assert results['Items'][1]['body'] == 'yet another test message'
|
assert results['Items'][1]['body'] == 'yet another test message'
|
||||||
|
|
||||||
|
# The projection expression should not remove data from storage
|
||||||
|
results = table.query(
|
||||||
|
KeyConditionExpression=Key('forum_name').eq(
|
||||||
|
'the-key'),
|
||||||
|
)
|
||||||
|
assert 'subject' in results['Items'][0]
|
||||||
|
assert 'body' in results['Items'][1]
|
||||||
|
assert 'forum_name' in results['Items'][1]
|
||||||
|
|
||||||
|
|
||||||
@mock_dynamodb2
|
@mock_dynamodb2
|
||||||
def test_basic_projection_expressions_with_attr_expression_names():
|
def test_basic_projection_expressions_with_attr_expression_names():
|
||||||
|
Loading…
Reference in New Issue
Block a user