Q:

Python decorated function unable to return the correct value

I have written this code to decorate a function if the underlying sql scripts being called is too noisy. The gp_info_decorator(function) modifies the execute_gp_func() to suppress messages from the sql scripts. Instead, it just stores the result in the Status variable.
But, the decorated function is returning None, instead of current date.
import sys
import psycopg2
import json
import os
#import contextlib.contextmanager
import sys

#  functions to train and predict
class GetExecutor:

    #global props
    # create instance variables from the properties file

    def __init__(self,home_dir, os_type = "linux"):
        if sys.platform in ('linux', 'linux2'):
            self.home_dir = home_dir
            self.os_type = 'linux'
            self.dbname = None
            self.user = None
            self.host = None
            self.passwd = None
            self.conn = None

        elif sys.platform in ('win32'):
            self.home_dir = home_dir
            self.os_type = 'windows'
            self.dbname = None
            self.user = None
            self.host = None
            self.passwd = None
            self.conn = None

    def read_properties(self):
        with open('properties.json', 'r') as f1:
            props = json.load(f1)
            self.dbname = props['dbname']
            self.user = props['user']
            self.host = props['host']
            self.passwd = props['passwd']
            #self.start_date = props['start_date']
            #self.end_date = props['end_date']
        print ("Properties stored")
        return props

    # sql connector
    def sql_connect(self):
        try:
            connect_string = "dbname = %s user = %s host = %s password = %s"%(self.dbname, self.user, self.host, self.passwd)
            conn = psycopg2.connect(connect_string)
            conn.set_isolation_level(0)
            print ("Connecting --")
        except:
            print "Unable to connect to the database"
        self.conn = conn

    # suppress logger info from sql if it is too much noise during execution
    def gp_info_decorator(function):
        def wrapper(*args, **kwargs):
            #print args[0].home_dir
            #print args[0].query
            #with open(sys.stdout, "w") as devnull:
            function(*args, **kwargs)
            """
            with open(os.devnull, "w") as devnull:
                old_stdout = sys.stdout
                sys.stdout = devnull
                try:
                    function(*args, **kwargs)
                finally:
                    sys.stdout = old_stdout
            """
            print ("Debug 3--->", wrapper)
        return wrapper

    # Execute training
    @gp_info_decorator
    def execute_gp_func(self, home_dir, query):
        print ("Function Name:", query)
        with self.conn.cursor() as cursor:
            cursor.execute(query)
            print "Executing-->"
            Status= cursor.fetchall()
            print ("Status is ", Status)
        for notice in self.conn.notices:
            print notice
        print ("Debug 2--->", Status)
            #Status = 
        return Status    

def main():
    home_dir = os.getcwd()
    print home_dir
    obj = GetExecutor(home_dir)
    print obj
    props = obj.read_properties()
    obj.sql_connect()

    #status = obj.execute_gp_func(home_dir,"select get_analytic.fn_get_logistics_train_data(%s,%s);"%(props['start_date'],props['end_date']))
    status = obj.execute_gp_func(home_dir,"select current_date")
    print ("Status of load cost training:" , status)

    # Bill process date date params
    #status = obj.execute_gp_func(home_dir,"select get_analytic.fn_get_logistics_bill_date_train(%s,%s);"%(props['start_date'],props['end_date']))
    print ("Status of bill process date training:" , status)

if __name__ == '__main__':
    main()

On execution, I see that the print within function has correct value for date. But, it goes into the wrapper and then returns the None value.
<__main__.GetExecutor instance at 0x000000000AE8DE48>
Properties stored
Connecting --
('Function Name:', 'select current_date')
Executing-->
('Status is ', [(datetime.date(2017, 8, 29),)])
('Debug 2--->', [(datetime.date(2017, 8, 29),)])
('Debug 3--->', <function wrapper at 0x000000000AE56AC8>)
('Status of load cost training:', None)
('Status of bill process date training:', None)

A:

Looks as if your wrapper only calls the function, but does nothing with the return value:
def gp_info_decorator(function):
    def wrapper(*args, **kwargs):
        #print args[0].home_dir
        #print args[0].query
        #with open(sys.stdout, "w") as devnull:
        result = function(*args, **kwargs) # <-- remember result
        """
        ... # <-- removed for readability
        """
        print ("Debug 3--->", wrapper)
        return result # <-- return result
    return wrapper

@gp_info_decorator
def fn1():
    return 5

r = fn1()
print(r) # Output: 5

