-
Notifications
You must be signed in to change notification settings - Fork 12
Description
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.