Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Serialize empty strings #151

Merged
merged 1 commit into from
Mar 24, 2021

Conversation

Hazelfire
Copy link
Contributor

Fixes #144, allowing empty strings to be included in the serialization.

This seems to be an explicit bug, I am not sure why these statements would be here

@ramosbugs
Copy link

I suspect it's because of this quirk of PutRequest inside BatchWriteItem:

Attribute values must not be null; string and binary type attributes must have lengths greater than zero; and set type attributes must not be empty. Requests that contain empty values are rejected with a ValidationException exception.

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html#API_BatchWriteItem_RequestParameters

however, regular PutItem requests do support empty strings:

Empty String and Binary attribute values are allowed.

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html#API_PutItem_RequestParameters

I'm running into the same issue as @Hazelfire. my suggestion would be either to have two modes of serialization, or to allow serializing empty strings and to make it the caller's responsibility to use, e.g., #[serde(skip_serializing_if = "...")] to avoid serializing empty strings when using BatchWriteItem. thoughts?

@veedubyou
Copy link

I'm running into the same issue as @Hazelfire. my suggestion would be either to have two modes of serialization, or to allow serializing empty strings and to make it the caller's responsibility to use, e.g., #[serde(skip_serializing_if = "...")] to avoid serializing empty strings when using BatchWriteItem. thoughts?

imo it makes little sense to let the library silently side step these validation issues - if there was an error then either the library should just let dynamodb report it back, or the library itself should return a failure. I imagine if I did a batch write with many items and some empty string attributes, I'd be very surprised to see my attribute missing in the bulk of my items on later retrieval.

@Hazelfire
Copy link
Contributor Author

Hazelfire commented Mar 23, 2021

I believe that is actually a documentation error (PutRequest inside BatchWriteItem). I tested it and PutRequest in BatchWriteItem allows for empty attributes.

This seems to be here due to an oversight in changing to support this in 2018 (citing aws/aws-sdk-java#1189). So the best way to proceed is to merge this request to reflect the change in behavior.

I submitted feedback on this documentation for AWS.

Base automatically changed from master to main March 24, 2021 00:51
@mockersf
Copy link
Owner

thank you for checking this!

@mockersf mockersf merged commit 76aa379 into mockersf:main Mar 24, 2021
mockersf added a commit that referenced this pull request Mar 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty string fields do not get serialized
4 participants