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

Update operations treat empty string as null #605

Open
cdurante opened this issue Oct 12, 2023 · 0 comments
Open

Update operations treat empty string as null #605

cdurante opened this issue Oct 12, 2023 · 0 comments

Comments

@cdurante
Copy link

cdurante commented Oct 12, 2023

DynamoDB has supported empty values since 2020

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/

However, when creating an update transaction. DDB toolbox treats an update of a string field to empty as equivalent to removing it. If this attribute happens to be required an error is thrown.

See src/classes/Entity/Entity.ts

 else if (
        this._table!._removeNulls === true &&
        (data[field] === null || String(data[field]).trim() === '') &&
        !Array.isArray(data[field]) &&
        (!mapping.link || mapping.save)
      ) {
        // Verify attribute is not required
        if (schema.attributes[field].required) error(`'${field}' is required and cannot be removed`)
        REMOVE.push(`#${field}`)
        names[`#${field}`] = field
      }

It is OK for a required field to contain empty string as long as it is not PK/SK

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

1 participant