# Buggy code
def run(self):
    """Runs Task Instance."""
    dag_id = request.form.get("dag_id")
    task_id = request.form.get("task_id")
    origin = get_safe_url(request.form.get("origin"))
    dag = current_app.dag_bag.get_dag(dag_id)
    task = dag.get_task(task_id)

    execution_date = request.form.get("execution_date")
    execution_date = timezone.parse(execution_date)
    ignore_all_deps = request.form.get("ignore_all_deps") == "true"
    ignore_task_deps = request.form.get("ignore_task_deps") == "true"
    ignore_ti_state = request.form.get("ignore_ti_state") == "true"

    executor = ExecutorLoader.get_default_executor()
    valid_celery_config = False
    valid_kubernetes_config = False

    try:
        from airflow.executors.celery_executor import CeleryExecutor  # noqa

        valid_celery_config = isinstance(executor, CeleryExecutor)
    except ImportError:
        pass

    try:
        from airflow.executors.kubernetes_executor import KubernetesExecutor  # noqa

        valid_kubernetes_config = isinstance(executor, KubernetesExecutor)
    except ImportError:
        pass

    if not valid_celery_config and not valid_kubernetes_config:
        flash("Only works with the Celery or Kubernetes executors, sorry", "error")
        return redirect(origin)

    ti = models.TaskInstance(task=task, execution_date=execution_date)
    ti.refresh_from_db()

    # Make sure the task instance can be run
    dep_context = DepContext(
        deps=RUNNING_DEPS,
        ignore_all_deps=ignore_all_deps,
        ignore_task_deps=ignore_task_deps,
        ignore_ti_state=ignore_ti_state,
    )
    failed_deps = list(ti.get_failed_dep_statuses(dep_context=dep_context))
    if failed_deps:
        failed_deps_str = ", ".join(
            [f"{dep.dep_name}: {dep.reason}" for dep in failed_deps]
        )
        flash(
            "Could not queue task instance for execution, dependencies not met: "
            "{}".format(failed_deps_str),
            "error",
        )
        return redirect(origin)

    executor.start()
    executor.queue_task_instance(
        ti,
        ignore_all_deps=ignore_all_deps,
        ignore_task_deps=ignore_task_deps,
        ignore_ti_state=ignore_ti_state,
    )
    executor.heartbeat()
    flash(f"Sent {ti} to the message queue, it should start any moment now.")
    return redirect(origin)


# Traceback (airflow.exceptions.AirflowException)
Something bad has happened.
Please consider letting us know by creating a bug report using GitHub.

Python version: 3.8.7
Airflow version: 2.0.0
Node: airflow-web-ffdd89d6-h98vj
-------------------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python3.8/site-packages/airflow/www/auth.py", line 34, in decorated
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/airflow/www/decorators.py", line 60, in wrapper
return f(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/airflow/www/views.py", line 1366, in run
executor.start()
File "/usr/local/lib/python3.8/site-packages/airflow/executors/kubernetes_executor.py", line 493, in start
raise AirflowException("Could not get scheduler_job_id")
airflow.exceptions.AirflowException: Could not get scheduler_job_id

# Fixed code
def run(self):
    """Runs Task Instance."""
    dag_id = request.form.get("dag_id")
    task_id = request.form.get("task_id")
    origin = get_safe_url(request.form.get("origin"))
    dag = current_app.dag_bag.get_dag(dag_id)
    task = dag.get_task(task_id)

    execution_date = request.form.get("execution_date")
    execution_date = timezone.parse(execution_date)
    ignore_all_deps = request.form.get("ignore_all_deps") == "true"
    ignore_task_deps = request.form.get("ignore_task_deps") == "true"
    ignore_ti_state = request.form.get("ignore_ti_state") == "true"

    executor = ExecutorLoader.get_default_executor()
    valid_celery_config = False
    valid_kubernetes_config = False

    try:
        from airflow.executors.celery_executor import CeleryExecutor  # noqa

        valid_celery_config = isinstance(executor, CeleryExecutor)
    except ImportError:
        pass

    try:
        from airflow.executors.kubernetes_executor import KubernetesExecutor  # noqa

        valid_kubernetes_config = isinstance(executor, KubernetesExecutor)
    except ImportError:
        pass

    if not valid_celery_config and not valid_kubernetes_config:
        flash("Only works with the Celery or Kubernetes executors, sorry", "error")
        return redirect(origin)

    ti = models.TaskInstance(task=task, execution_date=execution_date)
    ti.refresh_from_db()

    # Make sure the task instance can be run
    dep_context = DepContext(
        deps=RUNNING_DEPS,
        ignore_all_deps=ignore_all_deps,
        ignore_task_deps=ignore_task_deps,
        ignore_ti_state=ignore_ti_state,
    )
    failed_deps = list(ti.get_failed_dep_statuses(dep_context=dep_context))
    if failed_deps:
        failed_deps_str = ", ".join(
            [f"{dep.dep_name}: {dep.reason}" for dep in failed_deps]
        )
        flash(
            "Could not queue task instance for execution, dependencies not met: "
            "{}".format(failed_deps_str),
            "error",
        )
        return redirect(origin)

    executor.job_id = "manual"
    executor.start()
    executor.queue_task_instance(
        ti,
        ignore_all_deps=ignore_all_deps,
        ignore_task_deps=ignore_task_deps,
        ignore_ti_state=ignore_ti_state,
    )
    executor.heartbeat()
    flash(f"Sent {ti} to the message queue, it should start any moment now.")
    return redirect(origin)