From bbb71f401c7fe0d83da593c62daeed9c316e4336 Mon Sep 17 00:00:00 2001 From: "SIPOS, Peter" Date: Wed, 16 Nov 2016 14:02:43 +0100 Subject: [PATCH] Add try block into domain.get_id_by_name function If we try to check if a domain exists, and we fetch with get_id_by_name() function it will return with None if the domain not exists, and return the id when yes. --- app/models.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models.py b/app/models.py index 7f14d40..f111e06 100644 --- a/app/models.py +++ b/app/models.py @@ -477,8 +477,11 @@ class Domain(db.Model): """ Return domain id """ - domain = Domain.query.filter(Domain.name==name).first() - return domain.id + try: + domain = Domain.query.filter(Domain.name==name).first() + return domain.id + except: + return None def update(self): """