Using objects.get() instead of objects()[0]

This commit is contained in:
Shay Nehmad 2019-07-22 17:42:20 +03:00
parent 89d49a7d3f
commit 92e400a66f
1 changed files with 6 additions and 6 deletions

View File

@ -42,16 +42,16 @@ class Monkey(Document):
@staticmethod @staticmethod
def get_single_monkey_by_id(db_id): def get_single_monkey_by_id(db_id):
try: try:
return Monkey.objects(id=db_id)[0] return Monkey.objects.get(id=db_id)
except IndexError: except mongoengine.DoesNotExist as ex:
raise MonkeyNotFoundError("id: {0}".format(str(db_id))) raise MonkeyNotFoundError("info: {0} | id: {1}".format(ex.message, str(db_id)))
@staticmethod @staticmethod
def get_single_monkey_by_guid(monkey_guid): def get_single_monkey_by_guid(monkey_guid):
try: try:
return Monkey.objects(guid=monkey_guid)[0] return Monkey.objects.get(guid=monkey_guid)
except IndexError: except mongoengine.DoesNotExist as ex:
raise MonkeyNotFoundError("guid: {0}".format(str(monkey_guid))) raise MonkeyNotFoundError("info: {0} | guid: {1}".format(ex.message, str(monkey_guid)))
@staticmethod @staticmethod
def get_latest_modifytime(): def get_latest_modifytime():