dynamodb2 - updated error message when UpdateItem with ConditionalExpression fails (#4375)
This commit is contained in:
		
							parent
							
								
									7d660b236f
								
							
						
					
					
						commit
						6fdb62a0a5
					
				@ -855,9 +855,7 @@ class DynamoHandler(BaseResponse):
 | 
				
			|||||||
            return self.error(er, mve.exception_msg)
 | 
					            return self.error(er, mve.exception_msg)
 | 
				
			||||||
        except ValueError:
 | 
					        except ValueError:
 | 
				
			||||||
            er = "com.amazonaws.dynamodb.v20111205#ConditionalCheckFailedException"
 | 
					            er = "com.amazonaws.dynamodb.v20111205#ConditionalCheckFailedException"
 | 
				
			||||||
            return self.error(
 | 
					            return self.error(er, "The conditional request failed")
 | 
				
			||||||
                er, "A condition specified in the operation could not be evaluated."
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
        except TypeError:
 | 
					        except TypeError:
 | 
				
			||||||
            er = "com.amazonaws.dynamodb.v20111205#ValidationException"
 | 
					            er = "com.amazonaws.dynamodb.v20111205#ValidationException"
 | 
				
			||||||
            return self.error(er, "Validation Exception")
 | 
					            return self.error(er, "Validation Exception")
 | 
				
			||||||
 | 
				
			|||||||
@ -2877,7 +2877,7 @@ def test_condition_expressions():
 | 
				
			|||||||
        ExpressionAttributeValues={":match": {"S": "match"}},
 | 
					        ExpressionAttributeValues={":match": {"S": "match"}},
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    with pytest.raises(client.exceptions.ConditionalCheckFailedException):
 | 
					    with pytest.raises(client.exceptions.ConditionalCheckFailedException) as exc:
 | 
				
			||||||
        client.update_item(
 | 
					        client.update_item(
 | 
				
			||||||
            TableName="test1",
 | 
					            TableName="test1",
 | 
				
			||||||
            Key={"client": {"S": "client1"}, "app": {"S": "app1"}},
 | 
					            Key={"client": {"S": "client1"}, "app": {"S": "app1"}},
 | 
				
			||||||
@ -2886,6 +2886,18 @@ def test_condition_expressions():
 | 
				
			|||||||
            ExpressionAttributeValues={":match": {"S": "match"}},
 | 
					            ExpressionAttributeValues={":match": {"S": "match"}},
 | 
				
			||||||
            ExpressionAttributeNames={"#existing": "existing", "#match": "match"},
 | 
					            ExpressionAttributeNames={"#existing": "existing", "#match": "match"},
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					    _assert_conditional_check_failed_exception(exc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    with pytest.raises(client.exceptions.ConditionalCheckFailedException) as exc:
 | 
				
			||||||
 | 
					        client.update_item(
 | 
				
			||||||
 | 
					            TableName="test1",
 | 
				
			||||||
 | 
					            Key={"client": {"S": "client2"}, "app": {"S": "app1"}},
 | 
				
			||||||
 | 
					            UpdateExpression="set #match=:match",
 | 
				
			||||||
 | 
					            ConditionExpression="attribute_exists(#existing)",
 | 
				
			||||||
 | 
					            ExpressionAttributeValues={":match": {"S": "match"}},
 | 
				
			||||||
 | 
					            ExpressionAttributeNames={"#existing": "existing", "#match": "match"},
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					    _assert_conditional_check_failed_exception(exc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    with pytest.raises(client.exceptions.ConditionalCheckFailedException):
 | 
					    with pytest.raises(client.exceptions.ConditionalCheckFailedException):
 | 
				
			||||||
        client.delete_item(
 | 
					        client.delete_item(
 | 
				
			||||||
@ -2897,6 +2909,12 @@ def test_condition_expressions():
 | 
				
			|||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def _assert_conditional_check_failed_exception(exc):
 | 
				
			||||||
 | 
					    err = exc.value.response["Error"]
 | 
				
			||||||
 | 
					    err["Code"].should.equal("ConditionalCheckFailedException")
 | 
				
			||||||
 | 
					    err["Message"].should.equal("The conditional request failed")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@mock_dynamodb2
 | 
					@mock_dynamodb2
 | 
				
			||||||
def test_condition_expression_numerical_attribute():
 | 
					def test_condition_expression_numerical_attribute():
 | 
				
			||||||
    dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
 | 
					    dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
 | 
				
			||||||
@ -2972,8 +2990,9 @@ def test_condition_expression__attr_doesnt_exist():
 | 
				
			|||||||
    update_if_attr_doesnt_exist()
 | 
					    update_if_attr_doesnt_exist()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Second time should fail
 | 
					    # Second time should fail
 | 
				
			||||||
    with pytest.raises(client.exceptions.ConditionalCheckFailedException):
 | 
					    with pytest.raises(client.exceptions.ConditionalCheckFailedException) as exc:
 | 
				
			||||||
        update_if_attr_doesnt_exist()
 | 
					        update_if_attr_doesnt_exist()
 | 
				
			||||||
 | 
					    _assert_conditional_check_failed_exception(exc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@mock_dynamodb2
 | 
					@mock_dynamodb2
 | 
				
			||||||
@ -3012,7 +3031,7 @@ def test_condition_expression__and_order():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    # ensure that the RHS of the AND expression is not evaluated if the LHS
 | 
					    # ensure that the RHS of the AND expression is not evaluated if the LHS
 | 
				
			||||||
    # returns true (as it would result an error)
 | 
					    # returns true (as it would result an error)
 | 
				
			||||||
    with pytest.raises(client.exceptions.ConditionalCheckFailedException):
 | 
					    with pytest.raises(client.exceptions.ConditionalCheckFailedException) as exc:
 | 
				
			||||||
        client.update_item(
 | 
					        client.update_item(
 | 
				
			||||||
            TableName="test",
 | 
					            TableName="test",
 | 
				
			||||||
            Key={"forum_name": {"S": "the-key"}},
 | 
					            Key={"forum_name": {"S": "the-key"}},
 | 
				
			||||||
@ -3021,6 +3040,7 @@ def test_condition_expression__and_order():
 | 
				
			|||||||
            ExpressionAttributeNames={"#ttl": "ttl"},
 | 
					            ExpressionAttributeNames={"#ttl": "ttl"},
 | 
				
			||||||
            ExpressionAttributeValues={":ttl": {"N": "6"}, ":old_ttl": {"N": "5"}},
 | 
					            ExpressionAttributeValues={":ttl": {"N": "6"}, ":old_ttl": {"N": "5"}},
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					    _assert_conditional_check_failed_exception(exc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@mock_dynamodb2
 | 
					@mock_dynamodb2
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user