# Buggy code
def run(self, low):
    """
    Execute the specified function in the specified state by passing the
    low data
    """
    l_fun = getattr(self, low["state"])
    try:
        f_call = salt.utils.format_call(l_fun, low)
        kwargs = f_call.get("kwargs", {})

        # TODO: Setting the user doesn't seem to work for actual remote publishes
        if low["state"] in ("runner", "wheel"):
            # Update called function's low data with event user to
            # segregate events fired by reactor and avoid reaction loops
            kwargs["__user__"] = self.event_user

        l_fun(*f_call.get("args", ()), **kwargs)
    except Exception:
        log.error(
            "Failed to execute {0}: {1}\n".format(low["state"], l_fun), exc_info=True
        )


# Traceback (nTypeError)
my_test_event	{
"_stamp": "2017-01-20T08:29:41.956660",
"cmd": "_minion_event",
"data": {
"__pub_fun": "event.send",
"__pub_jid": "20170120092941938085",
"__pub_pid": 14303,
"__pub_tgt": "salt-call"
},
"id": "my_saltmaster",
"tag": "my_test_event"
}
salt/job/20170120092941973697/ret/my_saltmaster	{
"_stamp": "2017-01-20T08:29:41.976136",
"arg": [
"my_test_event"
],
"cmd": "_return",
"fun": "event.send",
"fun_args": [
"my_test_event"
],
"id": "my_saltmaster",
"jid": "20170120092941973697",
"retcode": 0,
"return": true,
"tgt": "my_saltmaster",
"tgt_type": "glob"
}
salt/run/20170120092942802583/new	{
"_stamp": "2017-01-20T08:29:42.806233",
"fun": "runner.cloud.action",
"fun_args": [
{
"__id__": "cloudrunner",
"__sls__": "/srv/reactor/my_test_reactor.sls",
"cloudmap": null,
"func": "disable_term_protect",
"instance": "my_minion",
"instances": null,
"name": "cloudrunner",
"order": 1,
"provider": null,
"state": "runner"
}
],
"jid": "20170120092942802583",
"user": "Reactor"
}
salt/run/20170120092942802583/ret	{
"_stamp": "2017-01-20T08:29:43.049610",
"fun": "runner.cloud.action",
"fun_args": [
{
"__id__": "cloudrunner",
"__sls__": "/srv/reactor/my_test_reactor.sls",
"cloudmap": null,
"func": "disable_term_protect",
"instance": "my_minion",
"instances": null,
"name": "cloudrunner",
"order": 1,
"provider": null,
"state": "runner"
}
],
"jid": "20170120092942802583",
"return": "Exception occurred in runner cloud.action: Traceback (most recent call last):\n  File \"/usr/lib/python2.7/dist-packages/salt/client/mixins.py\", line 395, in _low\n    data['return'] = self.functions[fun](*args, **kwargs)\n  File \"/usr/lib/python2.7/dist-packages/salt/runners/cloud.py\", line 154, in action\n    info = client.action(func, cloudmap, instances, provider, instance, **_filter_kwargs(kwargs))\nTypeError: action() got an unexpected keyword argument 'state'\n",
"success": false,
"user": "Reactor"
}

# Fixed code
def run(self, low):
    """
    Execute the specified function in the specified state by passing the
    low data
    """
    l_fun = getattr(self, low["state"])
    try:
        f_call = salt.utils.format_call(l_fun, low)
        kwargs = f_call.get("kwargs", {})

        # TODO: Setting the user doesn't seem to work for actual remote publishes
        if low["state"] in ("runner", "wheel"):
            # Update called function's low data with event user to
            # segregate events fired by reactor and avoid reaction loops
            kwargs["__user__"] = self.event_user
            # Replace ``state`` kwarg which comes from high data compiler.
            # It breaks some runner functions and seems unnecessary.
            kwargs["__state__"] = kwargs.pop("state")

        l_fun(*f_call.get("args", ()), **kwargs)
    except Exception:
        log.error(
            "Failed to execute {0}: {1}\n".format(low["state"], l_fun), exc_info=True
        )