def wrap_clause_in_parens(sql):
 if sql.strip():
  sql = u'({})'.format(sql)
 return sa.text(sql)

def wrap_clause_in_parens ( sql ) : if sql . strip ( ) : sql = u'({})' . format ( sql ) return sa . text ( sql )
wrap where/having clause with parenthesis if necessary .