Boto3: Error Message could be more useful in dynamodb batch_writer()

Created on 13 Sep 2017  路  2Comments  路  Source: boto/boto3

In testing, had found a client error ClientError as follows:

An error occurred (ValidationException) when calling the BatchWriteItem operation: One or more parameter values were invalid: An AttributeValue may not contain an empty string

However, if I immediately put the same item via the regular put_item method, it worked fine. I used the code straight out of the docs, as follows:

Code

    with ACCOUNTS_TABLE.batch_writer() as batch:
        for item in items:
            try:
                batch.put_item(Item=item)
            except ClientError as e:
                print e.message
                print item
                ACCOUNTS_TABLE.put_item(Item=item)
                print "successfully posted via regular put_item"

Output

An error occurred (ValidationException) when calling the BatchWriteItem operation: One or more parameter values were invalid: An AttributeValue may not contain an empty string
{'acc_short_name': 'name', 'account_id': '000000000000', 'secrets': {'external_id_1': 'randomstring', 'external_id_2': 'randomstring'}, 'canonical_user_id': 'randomstring', 'environments': ['[null]', 'hub'], 'available_volumes_prune': True, 'regions': ['us-west-2'], 'client': 'client name', 'listed': True, 'acc_description': None}
successfully posted via regular put_item

After turning on debug logging on botocore, it turned out that in the background it was batching up all of the items, and even though the error came up with this specific item, it was actually a totally different item that in the batch that was causing the problem.

Suggestion

ClientError should have a two new attributes:

  • api_call (or something like that) - details of what API and what method in the API was being invoked
  • params - a dictionary of the kwargs sent to the API
auto-label-exempt confusing-error feature-request

Most helpful comment

Marking as a feature request.

All 2 comments

Marking as a feature request.

I'd also really appreciate a more useful error in this case or perhaps a way to access the current items in the batch so they can be logged out manually?

Was this page helpful?
0 / 5 - 0 ratings