Skip to content

Possibility to raise more specific exception when the table does not exist #143

@huyphan

Description

@huyphan

I can contribute PR for this but I'm leaving the issue here first to collect some thoughts.

Currently if we skip creating table when binding a model and the table does not exist yet, loading objects will result generic exception bloop.exceptions.BloopException:

In [7]: from bloop import BaseModel, String, Engine
   ...:
   ...:
   ...: class UserModel(BaseModel):
   ...:     id = Column(String, hash_key=True)
   ...:     name = Column(String)
   ...:
   ...: engine = Engine()
   ...: engine.bind(UserModel, skip_table_setup=True)
   ...:
   ...: try:
   ...:     model = UserModel(id="Foo")
   ...:     engine.load(model, consistent=True)
   ...: except Exception as ex:
   ...:     print(f"Exception type: {type(ex)}")
   ...:     print(f"Exception message: {ex}")
   ...:

Exception type: <class 'bloop.exceptions.BloopException'>
Exception message: Unexpected error while loading items.

I enabled debug log and found the underlying exception returned by DynamoDB:

2020-01-14 04:13:08,399 [DEBUG] Response body:
b'{"__type":"com.amazonaws.dynamodb.v20120810#ResourceNotFoundException","message":"Requested resource not found"}'

For get_item/batch_get_item API, I think it's safe to assume that ResourceNotFoundException is only returned when the table does not exist. Hence we should be able to raise a specific exception here.

The issue with that assumption is that it might not be future-proof. So one safe option is to still return a generic exception, but less generic than BloopException -- I'm thinking of MissingResource so it's consistent with existing MIssingObjects exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions