使用 aws/aws-sdk-php 3.21.6。当 ConditionExpression 遇到 ConditionalCheckFailedException 错误时,我一定误解了 ReturnValues 的工作原理。
我希望的是,如果 ConditionExpression 失败,进而触发 ConditionalCheckFailedException,我可以捕获此异常,然后通过 ReturnValues 访问 DD 中的新属性。
我期望从 ReturnValues 获得的文档属性似乎暗示了这一点。
然而,根据测试,ReturnValues 仅在 ConditionExpression 为 true 时返回属性,而不是在失败时返回属性。
$response = $client->updateItem([
'TableName' => 'MyTable',
'Key' => [
'customer_url' => [
'S' => 'someurl.com'
],
'customer_platform' => [
'S' => 'some_platform'
]
],
'ExpressionAttributeNames' => [
'#C' => 'createdAt'
],
'ExpressionAttributeValues' => [
':val1' => [
'S' => '2017-01-24T14:15:32'
],
':val2' => [
'S' => '2017-01-24T14:15:30'
]
],
'UpdateExpression' => 'set #C = :val1',
'ConditionExpression' => '#C = :val2', // :val2 originally was 2017-01-24T14:15:30, before attempting to update to 2017-01-24T14:15:32. If I change the field to 2017-01-24T14:15:31, before running this update it will throw the ConditionalCheckFailedException
'ReturnValues' => 'ALL_NEW'
]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7902 次 |
| 最近记录: |