in modular_sdk/models/pynamodb_extension/pynamodb_to_pymongo_adapter.py [0:0]
def get_nullable(self, model_class, hash_key, sort_key=None
) -> Optional[Model]:
hash_key_name, range_key_name = self.__get_table_keys(model_class)
if not hash_key_name:
raise AssertionError('Can not identify the hash key name of '
f'model: \'{type(model_class).__name__}\'')
if sort_key and not range_key_name:
raise AssertionError(
f'The range key value is specified for '
f'model \'{type(model_class).__name__}\' but there is no '
f'attribute in the model marked as range_key')
collection = self._collection_from_model(model_class)
params = {hash_key_name: hash_key}
if range_key_name and sort_key:
params[range_key_name] = sort_key
raw_item = collection.find_one(params)
if raw_item:
raw_item = self.mongodb.decode_keys(raw_item)
return model_class.from_json(raw_item)