DynamoDB UpdateItem with ReturnValues parameter returns nothing on failed ConditionExpression - amazon-dynamodb

Using aws/aws-sdk-php 3.21.6. I must be misunderstanding how ReturnValues works when a ConditionExpression meets the ConditionalCheckFailedException error.
What I'm hoping is that if the ConditionExpression fails, which in turn triggers the ConditionalCheckFailedException, that I can catch this exception and then get access via ReturnValues to the new Attributes from DD.
The docs Attributes I'm expecting from ReturnValues seem to imply this.
From testing, however, ReturnValues only returns Attributes if the ConditionExpression is true, not when it fails.
$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'
]);

Yes, ReturnValues is populated only if an updateItem succeeds. If it fails, because of ConditionalCheckFailedException or any other reason, ReturnValues will be null.
Supporting documentation from here, with emphasis mine:
Use ReturnValues if you want to get the item attributes as they appeared either before or after they were updated.

Related

Token XRPL listing

I am trying to list a token of XRPL, set truct and receive the following
"error_message" => "Field 'tx_json.LimitAmount' has invalid data."
"request" => array:5 [▼
"command" => "submit"
"fee_mult_max" => 1000
"offline" => false
"secret" => "<masked>"
"tx_json" => array:6 [▼
"Account" => "rX49UBNi94tCCt2jb7tHVjdYSVwHNhQK2"
"DestinationTag" => 1
"Fee" => "15000"
"Flags" => 262144
"LimitAmount" => array:3 [▼
"currency" => "Xoge"
"issuer" => "rJMtvf5B3GbuFMrqybh5wYVXEH4QE8VyU1"
"value" => "1000000000000000"
]
"TransactionType" => "TrustSet"
]
]
"status" => "error"
using this document: https://xrpl.org/trustset.html
XRP Ledger supports either a three-letter ISO 4217 Currency Code or a 160-bit(40-character) hexadecimal string as value for "currency" field.
In your case(above code), you are using "Xoge" as value for the field "currency" inside "LimitAmount" object. "Xoge" has more than 3 letters, so it's throwing error. You can either switch to a 3 letter currency code or convert "Xoge" into 160-bit(40-character) hexadecimal string.
LimitAmount: {
currency: '586F676500000000000000000000000000000000',
issuer: 'rJMtvf5B3GbuFMrqybh5wYVXEH4QE8VyU1',
value: '1000000000000000'
},
Here 586F676500000000000000000000000000000000 represents Xoge in 160-bit hex.
Couple of more things I noticed from your code:
Fee is represented in drops. So you can lower your fee a bit, and it'll still work.
You are setting flag 262144 which enables rippling. Usually TrustLine is setup by regular users with the issuer, so it's always recommended to have flag 131072, which blocks rippling from the user end of the TrustLine.

Calling command asks for interaction even if I have set it to false

Using Symfony 5.4, I have created a command to run several commands (just to refresh my app quickly), here is my code:
// #see https://symfony.com/doc/current/console/calling_commands.html
$commands = [
'doctrine:schema:drop' => [
'--force' => true,
],
'doctrine:schema:update' => [
'--force' => true,
],
'doctrine:fixtures:load' => [
'-n' => true,
'--group' => ['dev'],
],
'fos:elastica:populate' => []
];
foreach ($commands as $command => $arguments) {
$output->writeln([
'Execute command',
$command,
'========================',
'',
]);
$command = $this->getApplication()->find($command);
$command->run(new ArrayInput($arguments), $output);
}
It's working fine, except the command doctrine:fixtures:load is asking for:
Careful, database "store" will be purged. Do you want to continue? (yes/no)
I have to set y to continue.
Looking at the help of the command, it seems -n (or --no-interaction) is what I want, and indeed, launching:
bin/console doctrine:fixtures:load --group=dev -n
manualy works fine.
Why the $arguments are not working for this command ? Did I miss something ?
Try this :
$nonInteractiveArguments = new ArrayInput($arguments);
$nonInteractiveArguments->setInteractive(false);
$command->run($nonInteractiveArguments, $output);
to set Input interactivity to false.

iOS application closes with no error when trying to retrieve push message data attribute

I'am sending push messages to application with react-native-firebase and it look's wonderful ! Also, I need to receive some portion of data, so sending data something like this
$request_body = [
'to' => $TOKEN_ID,
'notification' => [
'title' => 'Title',
'body' => 'Body',
'sound' => 'default',
],
'data' => [
'key' => 'value',
],
];
I'am trying to listen open push message event as bellow
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
const notification = notificationOpen.notification;
const data = notificationOpen.data;
setTimeout(() => {
Alert.alert(data.key);
}, 5000);
});
After 5 second left, application closes without any error message. If changing Alert.alert(data.key); with Alert.alert(notification.title); application work`s fine and show an alert. Can someone explain to me, why retrieving data is not work properly?
After some research, I found a solution
const data = notification.data;
or
const data = notificationOpen.notification.data;

Why symfony blocks when calling other controller?

I have two actions, and inside one action I am calling the other one but symfony block on that call until the first one (the one I am calling from) is finished. Therefore due to this fact i am getting time out error. Does anyone know what could be the reason ?
Action is rly simple:
$url = $this->router->generate(
'invoice_show',
[
'invoiceId' => $invoiceId,
],
UrlGeneratorInterface::ABSOLUTE_URL
);
return new Response(
$this->pdfGenerator->getOutput(
$url,
[
'margin-bottom' => 3,
'margin-top' => 3,
'margin-left' => 4,
'margin-right' => 4,
'disable-javascript' => true,
'load-error-handling' => 'ignore',
'cookie' => $request->cookies->all(),
]
),
200,
[
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="' . $invoiceId . '.pdf"',
]
);
Exception:
Symfony\Component\Process\Exception\ProcessTimedOutException(code:
0): The process \"/usr/bin/xvfb-run /usr/bin/wkhtmltopdf --lowquality
--margin-bottom '3' --margin-left '4' --margin-right '4' --margin-top '3' --disable-javascript --load-error-handling 'ignore'
'http://localhost/invoices/in_1Atlve2rN1gYNyHu4Ixmy8ZI'
'/var/www/var/cache/dev/snappy/knp_snappy599cffb13836d0.68608376.pdf'\"
exceeded the timeout of 60 seconds. at
/var/www/vendor/symfony/symfony/src/Symfony/Component/Process/Process.php:1265
Depending on the session handler which you use with symfony, it might lock the session until the first request is finished.
That means all subsequent requests will be blocked to prevent concurrency-issues while writing to the session (writing the same session in two requests might result in losing the first write).
It's the case with PDOSessionHandler, for example.
You can explicitly close the session by calling $request->session->save(); in your controller.
If you don't expect concurrency-issues, e.g. if you don't write to the session at all, you can also disable session locking for the whole application:
session.handler.pdo:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
public: false
arguments:
- "pgsql:host=%database_host%;port=%database_port%;dbname=%database_name%"
- db_username: %database_user%
db_password: %database_password%
db_table: session
db_id_col: session_id
db_data_col: session_value
db_time_col: session_time
db_lifetime_col: session_lifetime
lock_mode: 0

Accessing nested parameters in Symfony ParameterBag

Have a request that looks like this
ParameterBag {#362 ▼
#parameters: array:1 [▼
"form" => array:5 [▼
"titre" => "new b"
"prix" => "4444"
"slug" => "with-different-slug"
"publier" => "unpub"
"Modifier" => ""
]
]
}
How can I use the
$post = Request::createFromGlobals();
$post->request->has() on those nested properties?
ParameterBag's has function does not support deep check. It is just an array_key_exists call.
You could use get with $deep parameter set to true.
E.g.:
$post = Request::createFromGlobals();
$post->request->get('form[titre]', null, true);
It will return null (the second parameter), if the value does not exist.
EDIT:
This function however deprecated in 2.8.
Using paths to find deeper items in get is deprecated since version 2.8 and will be removed in 3.0. Filter the returned value in your own code instead.

Resources