I wrote a decorator function for handling database transactions and I want to be able to pass a logger to it.
My decorator function looks like
def handleTransactionAndCreateResponse(inner_func, logger):
"""
Runs inner function inside of a transaction, handles errors and returns a response.
Args:
inner_func: the function to wrap in a tranasction
logger: logger, used to log information.
"""
def wrapped_func(*args, **kwargs):
logger.info("Starting transaction")
# Other logic here
return inner_func(*args, **kwargs)
return wrapped_func
And I am calling it like
LOGGER = system.util.getLogger(__name__)
@forms2.decorators.handleTransactionAndCreateResponse(LOGGER)
def create(data, tx=None):
#Named queries here
return newId
However calling that create function, I get TypeError: handleTransactionAndCreateResponse() takes exactly 2 arguments (1 given)
So my decorator is expecting that logger to come through, I thought I was feeding it correctly with @forms2.decorators.handleTransactionAndCreateResponse(LOGGER)
but apparently not. What am I doing wrong here?