# Buggy code
def execute_async(
    self,
    key: TaskInstanceKey,
    command: CommandType,
    queue: Optional[str] = None,
    executor_config: Optional[Any] = None,
) -> None:
    """Executes task asynchronously"""
    self.log.info(
        "Add task %s with command %s with executor_config %s",
        key,
        command,
        executor_config,
    )
    kube_executor_config = PodGenerator.from_obj(executor_config)
    if executor_config:
        pod_template_file = executor_config.get("pod_template_override", None)
    else:
        pod_template_file = None
    if not self.task_queue:
        raise AirflowException(NOT_STARTED_MESSAGE)
    self.event_buffer[key] = (State.QUEUED, self.scheduler_job_id)
    self.task_queue.put((key, command, kube_executor_config, pod_template_file))


# Traceback (AttributeError)
[2021-02-10 21:09:27,469] {scheduler_job.py:1298} ERROR - Exception when executing SchedulerJob._run_schedu
ler_loop
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 1280, in _execute
self._run_scheduler_loop()
File "/usr/local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 1384, in _run_scheduler
_loop
self.executor.heartbeat()
File "/usr/local/lib/python3.8/site-packages/airflow/executors/base_executor.py", line 158, in heartbeat
self.trigger_tasks(open_slots)
File "/usr/local/lib/python3.8/site-packages/airflow/executors/base_executor.py", line 188, in trigger_ta
sks
self.execute_async(key=key, command=command, queue=None, executor_config=ti.executor_config)
File "/usr/local/lib/python3.8/site-packages/airflow/executors/kubernetes_executor.py", line 493, in exec
ute_async
kube_executor_config = PodGenerator.from_obj(executor_config)
File "/usr/local/lib/python3.8/site-packages/airflow/kubernetes/pod_generator.py", line 175, in from_obj
k8s_legacy_object = obj.get("KubernetesExecutor", None)
AttributeError: 'V1Pod' object has no attribute 'get'
[2021-02-10 21:09:28,475] {process_utils.py:100} INFO - Sending Signals.SIGTERM to GPID 60
[2021-02-10 21:09:29,222] {process_utils.py:66} INFO - Process psutil.Process(pid=66, status='terminated',
started='21:09:27') (66) terminated with exit code None
[2021-02-10 21:09:29,697] {process_utils.py:206} INFO - Waiting up to 5 seconds for processes to exit...
[2021-02-10 21:09:29,716] {process_utils.py:66} INFO - Process psutil.Process(pid=75, status='terminated',
started='21:09:28') (75) terminated with exit code None
[2021-02-10 21:09:29,717] {process_utils.py:66} INFO - Process psutil.Process(pid=60, status='terminated',
exitcode=0, started='21:09:27') (60) terminated with exit code 0
[2021-02-10 21:09:29,717] {scheduler_job.py:1301} INFO - Exited execute loop

# Fixed code
def execute_async(
    self,
    key: TaskInstanceKey,
    command: CommandType,
    queue: Optional[str] = None,
    executor_config: Optional[Any] = None,
) -> None:
    """Executes task asynchronously"""
    self.log.info(
        "Add task %s with command %s with executor_config %s",
        key,
        command,
        executor_config,
    )
    try:
        kube_executor_config = PodGenerator.from_obj(executor_config)
    except Exception:  # pylint: disable=broad-except
        self.log.error("Invalid executor_config for %s", key)
        self.fail(key=key, info="Invalid executor_config passed")
        return

    if executor_config:
        pod_template_file = executor_config.get("pod_template_override", None)
    else:
        pod_template_file = None
    if not self.task_queue:
        raise AirflowException(NOT_STARTED_MESSAGE)
    self.event_buffer[key] = (State.QUEUED, self.scheduler_job_id)
    self.task_queue.put((key, command, kube_executor_config, pod_template_file))