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.6k 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
}
asantibanez commented 7 years ago

+1

cbarcenas commented 7 years ago

+1

MerryOscar commented 7 years ago

+1

nfmelendez commented 7 years ago

+1

chaliy commented 7 years ago

+1, and at least be more specific in error message.

bwestergard commented 7 years ago

+1

jcready commented 7 years ago

@LiuJoyceC could you disclose whether this is something that is actually being worked on or even discussed internally? I only ask because this bug seems to be almost a half-decade old. So is this something that actually could be fixed but hasn't, or is it a fundamental limitation of the DynamoDB internal structure?

pzimny commented 7 years ago

Glad to see something is being done, but that's really just trading one problem for a new one.

enlightendata commented 7 years ago

+1

brandonmbanks commented 7 years ago

+1

jeskew commented 7 years ago

@brandonmbanks Converting empty values to null is now an opt-in feature of the document client; you can pass a boolean convertEmptyValues option to the document client constructor to have it do so. I'll open a PR to improve the documentation of this feature.

svoeller99 commented 7 years ago

+1

njgrisafi commented 7 years ago

+1

clearly commented 7 years ago

+1

pixelfuture commented 7 years ago

+1

ntrivix commented 7 years ago

+1

ruleechen commented 7 years ago

+1

elioncho commented 7 years ago

+1

yipcma commented 7 years ago

this is much needed, please...

jeskew commented 7 years ago

@yipcma As noted above, this has been implemented as an opt-in feature. Set the convertEmptyValues constructor option to true when creating a document client.

jcready commented 7 years ago

@jeskew I think what people want is the ability to store and retrieve an empty string. All this provides is a way to convert empty strings to null which really isn't the same thing.

jcready commented 7 years ago

People want to be able to store JSON documents in DynamoDB but right now we only have two options: 1) store the full JSON as a string in a single column, or 2) use convertEmptyValues and accept that you will not be able to use 100% of the JSON spec without data loss.

jeskew commented 7 years ago

Unfortunately, that isn't something that can be handled client-side without knowledge of the expected data schema.

If the SDK included a higher-level abstraction that knew which types certain fields were expected to be (like the AWS SDK for Java's DynamoDB Data Mapper or the Ruby Aws::Record), then the client could convert a null value to an empty string or empty buffer as appropriate. That's a reasonable feature request, but it's not something that could be built into the document client without introducing breaking changes.

Centurion commented 7 years ago

+1 from me +1 from Leanne

lamon commented 7 years ago

+1

jeremysuriel commented 7 years ago

+1

jstradli commented 7 years ago

+1

ashikkalavadiya commented 7 years ago

+1

rafiek commented 7 years ago

+1000

superandrew commented 7 years ago

ive never seen a issue desired like this one. Any roadmap to implement the possibility to store an empty string in dynamodb? should everyone move to another database? 🙏🏼

jeskew commented 7 years ago

@superandrew We've implemented opt-in, client-side support for this feature via the convertEmptyValues flag as discussed above.

superandrew commented 7 years ago

in my opinion, this is more of a client side patch for something that needs to be done on the dynamodb side. And, more importantly, and as someone else said before me, null is no replacement for an empty string. So if more and more people keeps asking for a more complete fix, I wouldn't call this issue "closed". But, of course, still my opinion.

jeskew commented 7 years ago

Just wanted to remind everyone to please keep the discussion constructive.

@superandrew I understand what you mean, but the SDK is a client-side library, and the DynamoDB team does not monitor the issue queue of any AWS SDK. For a server-side fix, I recommend that you reach out directly to the DynamoDB team via their AWS Developer Forum or via a support ticket.

ashikkalavadiya commented 7 years ago

@jeskew you can accelerate this type of request to AWS Team where plenty of people is facing issue with kind of problems! Though its almost 2 years, Developer finds a way on their(client) side as well!! LET IT GO!

jcready commented 7 years ago

@jeskew this bug is now more than half a decade old. No one seems to be getting satisfaction over there so they are voicing their concerns here. Perhaps AWS could open-source DynamoDB and put the code up on GitHub so we could create an issue there and/or make a PR which allows empty strings to be stored.

tsmiser commented 7 years ago

+1

thesnups commented 7 years ago

+1

amistein commented 7 years ago

+1

emaildanwilson commented 7 years ago

Slight change to the code suggested by @bo01ean so that it tokenizes and detokenizes the empty string. It works for me but it's annoying that I need to do this to preserve the original JSON when using dynamodb.

const token = '~&*^AWSSTILLHASNOTFIXEDTHIS!!!~&*^';

const tokenizeEmptyStringElements = function (obj) {
  for (var prop in obj) {
    if (typeof obj[prop] === 'object') {// dive deeper in
      tokenizeEmptyStringElements(obj[prop]);
    } else if(obj[prop] === '') {
      // tokenize elements that are empty strings
      obj[prop] = token
    }
  }
  return obj;
}

const detokenizeEmptyStringElements = function (obj) {
  for (var prop in obj) {
    if (typeof obj[prop] === 'object') {// dive deeper in
      detokenizeEmptyStringElements(obj[prop]);
    } else if(obj[prop] === token) {
      // tokenize elements that are empty strings
      obj[prop] = ''
    }
  }
  return obj;
}
ngocketit commented 7 years ago

+1

arvinkx commented 7 years ago

+1

svnlabs commented 7 years ago

AWS Error Type: client, AWS Error Message: One or more parameter values were invalid: An AttributeValue may not contain an empty string

Validate empty string with " " SPACE

MattTunny commented 7 years ago

+1

arctair commented 7 years ago

+1

eddyfabery commented 7 years ago

+1

terge commented 7 years ago

+1

vvemulak commented 7 years ago

+1

bo-ora commented 7 years ago

+1

bluepeter commented 7 years ago

+8

franciscotfmc commented 7 years ago

+1