Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty attribute values cannot be added to a DynamoDB table #1189

Closed
arun-gupta opened this issue Jun 8, 2017 · 23 comments
Closed

Empty attribute values cannot be added to a DynamoDB table #1189

arun-gupta opened this issue Jun 8, 2017 · 23 comments

Comments

@arun-gupta
Copy link

Adding the following document to a DynamoDB table:

{
  "id_str": "1",
  "foo": ""
}

gives the following error:

One or more parameter values were invalid: An AttributeValue may not contain an empty string (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: HPH1B0TUMQKHF0Q7SOMEOR5CKJVV4KQNSO5AEMVJF66Q9ASUAAJG)

This is a common use case and already fixed for https://github.com/aws/aws-sdk-js/pull/1283#issuecomment-306954767[JavaScript SDK]. It has caused enough frustration among customers. This is evident at https://forums.aws.amazon.com/thread.jspa?threadID=90137&start=0&tstart=0 and https://news.ycombinator.com/item?id=13170746 and should be fixed.

@arun-gupta arun-gupta changed the title Empty attribute values cannot be added to a table Empty attribute values cannot be added to a DynamoDB table Jun 8, 2017
@dagnir dagnir added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Jun 12, 2017
@shorea
Copy link
Contributor

shorea commented Jun 12, 2017

How did they fix this in Javascript? This is a service side limitation, attribute values cannot be created with an empty string value (not sure the exact reasoning for this). What is the expected behavior in the SDK?

@arun-gupta
Copy link
Author

Discussion at aws/aws-sdk-js#833

@shorea
Copy link
Contributor

shorea commented Jun 12, 2017

Ah I see, I am not crazy about the idea of adding a flag to ignore empty strings and treat them as null. We did something similar for the DDB mapper and it's surprising, possibly dangerous behavior since null and empty string do not have the same semantics and we are subtly hiding a service side limitation. That said an opt in approach seems reasonable. I've reached out to the service team to see if it's possible to relax the constraint on empty string as I think that would be the best solution, I'll let you know what I hear and we can go from there.

@lamon
Copy link

lamon commented Jun 27, 2017

+1

@shorea
Copy link
Contributor

shorea commented Sep 5, 2017

I've heard back from the DynamoDB team. They plan on supporting empty string sometime in 2018, no specific dates at the moment though. I'll update this issue if I get more information.

@shorea shorea closed this as completed Sep 5, 2017
@shorea shorea removed investigating This issue is being investigated and/or work is in progress to resolve the issue. waiting-service-reply labels Sep 5, 2017
@jobetdelima
Copy link

Hello @shorea, Any update on when this would be supported?

@paulupendo
Copy link

@shorea Any update on this? What I experienced is that if I have optional values on my request payload, DynamoDB populates a digit into the values on retrieval. This lead to the inability to retrieve all the values from DynamoDB on my GET requests due to parsing errors originating from the values DynamoDB was populating the optional fields with. So I resolved to provide a default value whenever a field value is not supplied when saving data to DynamoDB. However, a solution to enable storing of empty strings, especially when the field is optional will be awesome.

@niraj-bpsoftware
Copy link

Any update on this?

@wakahiu
Copy link

wakahiu commented Aug 31, 2018

I find it unacceptable that a database like this doesn't support empty strings or native floats, (you have to convert them to Decimal).

@hounded
Copy link

hounded commented Feb 23, 2019

any update?

@jhulfikarali
Copy link

We just started with DynamoDB and there you go, SURPRISE! I agree that empty doesn't make great sense in NoSQL but it would really help customers and would love to know if this has come to any fix after a year and a half wait time.

tapasvimoturu pushed a commit to tapasvimoturu/dynamite that referenced this issue Mar 17, 2019
@portinos
Copy link

any update? still waiting :(

@mikechambers610
Copy link

This should be a quick and easy thing to fix on the DynamoDB side. Where are the AWS pros at!?

This makes it so that you can not have any optional fields... any work arounds or answers?

@VladMasarik
Copy link

I have still not found a solution. Just another entry into my "Why I never want to use AWS" list.
So I created this:

def removeEmptyString(dic):
    for e in dic:
        if isinstance(dic[e], dict):
            dic[e] = removeEmptyString(dic[e])
        if (isinstance(dic[e], str) and dic[e] == ""):
            dic[e] = None
        if isinstance(dic[e], list):
            for entry in dic[e]:
                removeEmptyString(entry)
    return dic

dictionaryWithEmptyValuesReplacedWithNone = removeEmptyString(dicrionaryWithEmptyValues)

It is far from perfect but it works.

swen128 added a commit to swen128/vhub that referenced this issue Jun 26, 2019
DynamoDB does not accept objects with an empty string in its attribute.
See, e.g., aws/aws-sdk-java#1189
@hounded
Copy link

hounded commented Nov 6, 2019

@VladMasarik Yeah still waiting
I use the same for my appsync resolver in VTL land

    #if ( $context.arguments.input.vid == "" )
    "update" : {
        "expression" : "REMOVE vid",
    },
    #else
        "update" : {
        "expression" : "SET vid = :vid",
        "expressionValues": {
            ":vid" : { "S": "${context.arguments.input.vid}" },
        }
    },
   #end

Still a crappy work around as in the front end I need to find if null and then equate it to "" to make my tables work correctly

@PVautour
Copy link

I used an option when initialising the document client. Works as expected except for null displaying as true. This is, however, expected behaviour in dynamodb. Here is the example from my javascript code:

const documentClient = new AWS.DynamoDB.DocumentClient({convertEmptyValues: true});

@japadgett2
Copy link

Same here. const documentClient = new AWS.DynamoDB.DocumentClient({convertEmptyValues: true}) works for me.

@hugepanda
Copy link

It is already 2020 and I cannot believe aws still does not support empty string. Is this function in the plan or you guys just don't care? Please give us an answer here. Thank you.

@millems
Copy link
Contributor

millems commented Jan 20, 2020

I've reached out to the DynamoDB organization again regarding this issue.

DynamoDB is aware of the requirement and is still considering a fix for the issue. We know this response isn’t particularly satisfying, since the issue has been open for such a long time.

@mrajancsr
Copy link

i can believe after all these years this db can't support empty strings.

@fmontada
Copy link

My Solution

const convertEmptyValues = Item => {
	return JSON.parse(
		JSON.stringify(Item, (key, value) => {
			if (value === "" || value === null || value === undefined) {
				return undefined;
			}
			return value;
		})
	);
};

@leotohill
Copy link

DynamoDb now supports empty string values for non-key attributes: https://aws.amazon.com/about-aws/whats-new/2020/05/amazon-dynamodb-now-supports-empty-values-for-non-key-string-and-binary-attributes-in-dynamodb-tables/

@portcoding
Copy link

use update list to update the empty array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests