From 01f4cf1373c53e72a08bfa11bb37e57780405d0e Mon Sep 17 00:00:00 2001 From: Nadav Har'El Date: Mon, 8 Jul 2019 16:33:11 +0300 Subject: [PATCH] alternator-test: test UpdateItem's SET with #reference Test an operation like SET #one = #two, where the RHS has a reference to a name, rather than the name itself. Also verify that DynamoDB gives an error if ExpressionAttributeNames includes names not needed by neither left or right hand side of such assignments. Signed-off-by: Nadav Har'El Message-Id: <20190708133311.11843-1-nyh@scylladb.com> --- alternator-test/test_update_expression.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/alternator-test/test_update_expression.py b/alternator-test/test_update_expression.py index b0091b5438..8237068fae 100644 --- a/alternator-test/test_update_expression.py +++ b/alternator-test/test_update_expression.py @@ -53,6 +53,15 @@ def test_update_expression_set_copy(test_table_s): assert test_table_s.get_item(Key={'p': p}, ConsistentRead=True)['Item'] == {'p': p, 'a': 'hello', 'b': 'hello'} with pytest.raises(ClientError, match='ValidationException'): test_table_s.update_item(Key={'p': p}, UpdateExpression='SET z = z') + # We can also use name references in either LHS or RHS of SET, e.g., + # SET #one = #two. We need to also take the references used in the RHS + # when we want to complain about unused names in ExpressionAttributeNames. + test_table_s.update_item(Key={'p': p}, UpdateExpression='SET #one = #two', + ExpressionAttributeNames={'#one': 'c', '#two': 'a'}) + assert test_table_s.get_item(Key={'p': p}, ConsistentRead=True)['Item'] == {'p': p, 'a': 'hello', 'b': 'hello', 'c': 'hello'} + with pytest.raises(ClientError, match='ValidationException'): + test_table_s.update_item(Key={'p': p}, UpdateExpression='SET #one = #two', + ExpressionAttributeNames={'#one': 'c', '#two': 'a', '#three': 'z'}) # Test for read-before-write action where the value to be read is nested inside a - operator def test_update_expression_set_nested_copy(test_table_s):