From 389344489d59680a8913f593e07b9fa0fb6dbed1 Mon Sep 17 00:00:00 2001 From: mbauskar Date: Mon, 3 Jul 2017 15:54:39 +0530 Subject: [PATCH] [minor] return None is records are not available --- frappe/utils/nestedset.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frappe/utils/nestedset.py b/frappe/utils/nestedset.py index bb29077ca6..78a6b11810 100644 --- a/frappe/utils/nestedset.py +++ b/frappe/utils/nestedset.py @@ -239,9 +239,10 @@ class NestedSet(Document): def get_root_of(doctype): """Get root element of a DocType with a tree structure""" - return frappe.db.sql("""select t1.name from `tab{0}` t1 where + result = frappe.db.sql("""select t1.name from `tab{0}` t1 where (select count(*) from `tab{1}` t2 where - t2.lft < t1.lft and t2.rgt > t1.rgt) = 0""".format(doctype, doctype))[0][0] + t2.lft < t1.lft and t2.rgt > t1.rgt) = 0""".format(doctype, doctype)) + return result[0][0] if result else None def get_ancestors_of(doctype, name): """Get ancestor elements of a DocType with a tree structure"""