def METHOD_NAME(*args, **kwargs):
    """ "
    A decorator which creates a new session if one was not passed via keyword argument to the function.
    Automatically commits and closes the session if one was created, caller is responsible for commit if passed in.
    If arguments are given when used as a decorator, they will automatically be passed to the created Session when
    one is not supplied.
    """
    def decorator(func):
        def wrapper(*args, **kwargs):
            if kwargs.get('session'):
                return func(*args, **kwargs)
            with _Session() as session:
                kwargs['session'] = session
                return func(*args, **kwargs)
        return wrapper
    if len(args) == 1 and not kwargs and callable(args[0]):
        # Used without arguments, e.g. @with_session
        # We default to expire_on_commit being false, in case the decorated function returns db instances
        _Session = functools.partial(Session, expire_on_commit=False)
        return decorator(args[0])
    else:
        # Arguments were specified, turn them into arguments for Session creation e.g. @with_session(autocommit=True)
        _Session = functools.partial(Session, *args, **kwargs)
        return decorator