Merge pull request #2422 from kiyonori-matsumoto/dynamodb-and-order
fix: raises ValueError on conditional and operator
This commit is contained in:
commit
cbe1ff1974
@ -941,8 +941,7 @@ class OpAnd(Op):
|
||||
|
||||
def expr(self, item):
|
||||
lhs = self.lhs.expr(item)
|
||||
rhs = self.rhs.expr(item)
|
||||
return lhs and rhs
|
||||
return lhs and self.rhs.expr(item)
|
||||
|
||||
|
||||
class OpLessThan(Op):
|
||||
|
@ -2081,6 +2081,36 @@ def test_condition_expression__or_order():
|
||||
)
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_condition_expression__and_order():
|
||||
client = boto3.client('dynamodb', region_name='us-east-1')
|
||||
|
||||
client.create_table(
|
||||
TableName='test',
|
||||
KeySchema=[{'AttributeName': 'forum_name', 'KeyType': 'HASH'}],
|
||||
AttributeDefinitions=[
|
||||
{'AttributeName': 'forum_name', 'AttributeType': 'S'},
|
||||
],
|
||||
ProvisionedThroughput={'ReadCapacityUnits': 1, 'WriteCapacityUnits': 1},
|
||||
)
|
||||
|
||||
# ensure that the RHS of the AND expression is not evaluated if the LHS
|
||||
# returns true (as it would result an error)
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
client.update_item(
|
||||
TableName='test',
|
||||
Key={
|
||||
'forum_name': {'S': 'the-key'},
|
||||
},
|
||||
UpdateExpression='set #ttl=:ttl',
|
||||
ConditionExpression='attribute_exists(#ttl) AND #ttl <= :old_ttl',
|
||||
ExpressionAttributeNames={'#ttl': 'ttl'},
|
||||
ExpressionAttributeValues={
|
||||
':ttl': {'N': '6'},
|
||||
':old_ttl': {'N': '5'},
|
||||
}
|
||||
)
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_query_gsi_with_range_key():
|
||||
dynamodb = boto3.client('dynamodb', region_name='us-east-1')
|
||||
|
Loading…
Reference in New Issue
Block a user