aws / aws-sdk-js

AWS SDK for JavaScript in the browser and Node.js
https://aws.amazon.com/developer/language/javascript/
Apache License 2.0
7.59k stars 1.55k forks source link

DynamoDB.DocumentClient should support empty string properties #833

Closed thoean closed 7 years ago

thoean commented 8 years ago

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:

var params = {
    TableName: 'my-test-table',
    Item: { Key:"foo", MyData: ""}
};

Results in the following error on DynamoDB:

[AWS dynamodb 400 0.588s 0 retries] putItem({ TableName: 'my-test-table',
  Item: { Key: { S: 'foo' }, MyData: { S: '' } } })

Which is returned from the DocumentClient as:

Unable to store request. Error was {
  "message": "One or more parameter values were invalid: An AttributeValue may not contain an empty string",
  "code": "ValidationException",
  "time": "2015-12-10T09:19:17.204Z",
  "statusCode": 400,
  "retryable": false,
  "retryDelay": 0
}
chrisradek commented 8 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.

thoean commented 8 years ago

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.

RedaBenh commented 8 years ago

+1

brcline commented 8 years ago

+1

clicktravel-jaroslav commented 8 years ago

+1

LakerBaker commented 8 years ago

+1

hammadmlk commented 8 years ago

+1

jesucarr commented 8 years ago

+1

chandan449 commented 8 years ago

+1

simoami commented 8 years ago

+1

itaykahana commented 8 years ago

+1

bo01ean commented 8 years ago

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"
    }
  }
}
*/
pzimny commented 8 years ago

+1

joshwils82 commented 8 years ago

+1

manikandants commented 8 years ago

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.

LiuJoyceC commented 8 years ago

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.

John2496 commented 8 years ago

+1

ossie1971 commented 8 years ago

+1

lindell commented 8 years ago

+1

joegesualdo commented 8 years ago

+1

RhysC commented 8 years ago

+1

bradledford commented 8 years ago

+1

pavei commented 8 years ago

+1

dustinbolton commented 8 years ago

+1

amitatgit commented 8 years ago

+1

jppellerin commented 8 years ago

+1

cstavro commented 8 years ago

+1

kpx-dev commented 8 years ago

+1

iSkore commented 8 years ago

+1

CJNE commented 8 years ago

+1

tejasmanohar commented 8 years ago

+1

Rajkumar55 commented 8 years ago

+1

ghost commented 8 years ago

+1

guillaumefont commented 8 years ago

+1

seanchann commented 8 years ago

+1

superandrew commented 8 years ago

+1

rtrompier commented 8 years ago

+1

guillaumefont commented 8 years ago

+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 .

whiteswift commented 8 years ago

+1

csabakollar commented 8 years ago

+1

iSkore commented 8 years ago
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';
}
DianaIonita commented 7 years ago

+1

Imran99 commented 7 years ago

+1

jamie-reddell commented 7 years ago

+1

khoi-nguyen-2359 commented 7 years ago

+1

sasanala commented 7 years ago

+1

jbuddha commented 7 years ago

+1

Jorenm commented 7 years ago

+1

alistairg commented 7 years ago

+1

alexsolus commented 7 years ago

+1