Skip to content

Error Message could be more useful in dynamodb batch_writer() #1259

@flyinbutrs

Description

@flyinbutrs

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions