zio-aws icon indicating copy to clipboard operation
zio-aws copied to clipboard

DynamoDB - unexpected values set in AttributeValue

Open gchudnov opened this issue 2 years ago • 2 comments

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 AttributeValuein 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.

gchudnov avatar Apr 29 '22 00:04 gchudnov

Interseting, thank you for reporting. I will take a look, but my guess is that in the Java SDK level these are not nulls 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 avatar May 14 '22 08:05 vigoo

@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.

joprice avatar Aug 04 '23 16:08 joprice