Closed thoean closed 7 years ago
@thoean
What you're seeing is currently documented behavior:
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#putItem-property
String and Binary type attributes must have lengths greater than zero. Set type attributes cannot be empty. Requests with empty values will be rejected with a ValidationException exception.
This could be something we support in the future by having something like an ignoreEmptyStrings
configuration option for the DocumentClient
that was opt in.
Your proposal sounds great and would solve my use case.
Whether opt-in or standard behavior depends how much DocumentClient is a simplification over DynamoDB, not only in simplification of providing the necessary parameters, but also trying to do the right thing for the client. I think this case has arguments in both directions, so opt-in to maintain compatibility to its current version makes sense.
+1
+1
+1
+1
+1
+1
+1
+1
+1
I worked around this by just wiping out the empty keys from the object:
var Item = { Key:"foo", MyData: "", Item: { Key:"foo", MyData: "", Item: { Key:"foo", MyData: ""}}};
function removeEmptyStringElements(obj) {
for (var prop in obj) {
if (typeof obj[prop] === 'object') {// dive deeper in
removeEmptyStringElements(obj[prop]);
} else if(obj[prop] === '') {// delete elements that are empty strings
delete obj[prop];
}
}
return obj;
}
removeEmptyStringElements(Item);
/*
{
"Key": "foo",
"Item": {
"Key": "foo",
"Item": {
"Key": "foo"
}
}
}
*/
+1
+1
Do we have support for empty strings in the latest version? If not, any timeline for this feature to be available? I have a specific case where I am persisting the payment response with hash. If I remove the keys with empty strings, the hash generation would fail later.
Hi @manikandants
Unfortunately, we can't share a timeline for this, but thanks for everyone who has given a +1 or voiced a concern about this feature request, as it helps us prioritize. I will look into this as soon as I can.
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
On Fri, Oct 28, 2016 at 2:29 PM, rtrompier notifications@github.com wrote:
+1
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aws/aws-sdk-js/issues/833#issuecomment-256908063, or mute the thread https://github.com/notifications/unsubscribe-auth/ACTfBJDHiiE36MoAsD9aENTITv7zoTfaks5q4eqMgaJpZM4GykZr .
+1
+1
function cleanObj( o ) {
if( o && o === o )
if( typeof o === 'boolean' ) return o;
else if( typeof o === 'number' ) return o;
else if( typeof o === 'string' ) return o;
else if( Array.isArray( o ) ) {
let x = [], i = -1, l = o.length, r = 0;
while( ++i < l ) if( o[ i ] ) x[ r++ ] = cleanObj( o[ i ] );
return x;
} else if( typeof o === 'object' ) {
for( const k in o ) o[ k ] ? o[ k ] = cleanObj( o[ k ] ) : delete o[ k ];
return o;
} else
return 'Argument Error - Unknown Item';
}
+1
+1
+1
+1
+1
+1
+1
+1
+1
When the object contains a property with an empty string, it results in an exception instead of for example silently removing this property or replacing with a user-provided constant.
To be specific, the following example request:
Results in the following error on DynamoDB:
Which is returned from the DocumentClient as: