def get_ancestors_of(doctype, name):
 (lft, rgt) = frappe.db.get_value(doctype, name, [u'lft', u'rgt'])
 result = frappe.db.sql_list((u'select name from `tab%s`\n DCTB  DCTB where lft<%s and rgt>%s order by lft desc' % (doctype, u'%s', u'%s')), (lft, rgt))
 return (result or [])

def get_ancestors_of ( doctype , name ) : ( lft , rgt ) = frappe . db . get_value ( doctype , name , [ u'lft' , u'rgt' ] ) result = frappe . db . sql_list ( ( u'select name from `tab%s`\n DCTB  DCTB where lft<%s and rgt>%s order by lft desc' % ( doctype , u'%s' , u'%s' ) ) , ( lft , rgt ) ) return ( result or [ ] )
get ancestor elements of a doctype with a tree structure .