zio-aws
zio-aws copied to clipboard
DynamoDB - unexpected values set in AttributeValue
Hi,
When making a batchGetItem
reqest, a reponse received from the server is transformed to an unexpected BatchGetItemResponse.ReadOnly
-response (with some redundant fields).
For example, for the following response from the server:
{
"Responses": {
"History": [
{
"key": {
"S": "V9"
},
"version": {
"N": "-1049669123"
},
"records": {
"S": "123"
},
"value": {
"S": "yqKwfeak1sVV"
}
}
]
},
"UnprocessedKeys": {}
}
the attribute:
"key": {
"S": "V9"
},
is transformed to the following AttributeValue
in zio-aws:
0 = {Tuple2@9813} (country,zio.aws.dynamodb.model.AttributeValue$Wrapper@33aef772)
_2 = {AttributeValue$Wrapper@9821} zio.aws.dynamodb.model.AttributeValue$Wrapper@33aef772
s = {Some@9824} Some(V9)
n = {None$@9825} None
b = {None$@9825} None
ss = {Some@9826} Some(List())
ns = {Some@9827} Some(List())
bs = {Some@9828} Some(List())
m = {Some@9829} Some(Map())
l = {Some@9830} Some(List())
nul = {None$@9825} None
bool = {None$@9825} None
^
here we can see that all Iterables, like SS
, NS
, BS
, M
, etc. are set to Some(List())
, Some(Map())
.
the expected behavior is to set them to None
, since they were absent in the response from the server.
Interseting, thank you for reporting. I will take a look, but my guess is that in the Java SDK level these are not null
s either but empty collections. Not sure if treating those everywhere as None
is a valid solution (think of every AWS service's every operation)
@vigoo You are right. The docs say they will never return null:
This method will never return null. If you would like to know whether the service returned this field (so that you can differentiate between null and empty), you can use the hasL() method.
To wrap in an optional, you'd want to call hasL()
first to check if the field is set.