<p dir="auto"><strong>Apache Airflow version</strong>: 1.10.12<br>
<strong>Kubernetes version</strong>: 1.18.6</p>
<p dir="auto"><strong>What happened</strong>:<br>
Airflow is running within a k8s with <strong>KubernetesExecutor</strong><br>
When trying to run task on demand within a DAG (f.e. "Ignore all deps") receiving following banner</p>
<blockquote>
<p dir="auto">Only works with the Celery or Kubernetes executors, sorry</p>
</blockquote>
<p dir="auto"><strong>What you expected to happen</strong>:<br>
Task should be executed</p>
<p dir="auto"><strong>How to reproduce it</strong>:<br>
see above</p>
<p dir="auto"><strong>Apache Airflow version</strong>: 1.10.12</p>
<p dir="auto"><strong>Kubernetes version</strong> (if you are using kubernetes) (use kubectl version): v1.16.13-gke.401</p>
<p dir="auto"><strong>Environment</strong>: AWS EKS</p>
<ul dir="auto">
<li>Cloud provider or hardware configuration:</li>
<li>OS (e.g. from /etc/os-release):</li>
<li>Kernel (e.g. uname -a):</li>
<li>Install tools:</li>
<li>Others:**</li>
</ul>
<p dir="auto"><strong>What happened</strong>:</p>
<p dir="auto">Hi Airflow community <g-emoji class="g-emoji" alias="hand" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/270b.png">✋</g-emoji>  I have detected bug on Airflow webserver. I have deployed Airflow cluster that uses Kubernetes executor, runs on production AWS EKS cluster. All configurations are correct and runs successfully tasks on DAGs. But when I want to run specific task on DAG, that throws error like that:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/5066703/99072345-e7572d80-25c4-11eb-994c-d0081d79c715.png"><img src="https://user-images.githubusercontent.com/5066703/99072345-e7572d80-25c4-11eb-994c-d0081d79c715.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">But, I have checked my KubernetesExecutor configurations all of them are correct. So, I have digged error on source code of Airflow webserver at tag 1.10.12 which I have deployed version of Airflow. And found that some import errors are ignored for KubernetesExecutor on file <a href="https://github.com/apache/airflow/blob/1.10.12/airflow/www/views.py">https://github.com/apache/airflow/blob/1.10.12/airflow/www/views.py</a> at line 1152</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="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.contrib.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(&quot;Only works with the Celery or Kubernetes executors, sorry&quot;, &quot;error&quot;)
   return redirect(origin)"><pre class="notranslate"><span class="pl-s1">executor</span> <span class="pl-c1">=</span> <span class="pl-v">ExecutorLoader</span>.<span class="pl-en">get_default_executor</span>()
<span class="pl-s1">valid_celery_config</span> <span class="pl-c1">=</span> <span class="pl-c1">False</span>
<span class="pl-s1">valid_kubernetes_config</span> <span class="pl-c1">=</span> <span class="pl-c1">False</span>

<span class="pl-k">try</span>:
   <span class="pl-k">from</span> <span class="pl-s1">airflow</span>.<span class="pl-s1">executors</span>.<span class="pl-s1">celery_executor</span> <span class="pl-k">import</span> <span class="pl-v">CeleryExecutor</span>  <span class="pl-c"># noqa</span>

   <span class="pl-s1">valid_celery_config</span> <span class="pl-c1">=</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">executor</span>, <span class="pl-v">CeleryExecutor</span>)
<span class="pl-k">except</span> <span class="pl-v">ImportError</span>:
    <span class="pl-k">pass</span>

<span class="pl-k">try</span>:
  <span class="pl-k">from</span> <span class="pl-s1">airflow</span>.<span class="pl-s1">contrib</span>.<span class="pl-s1">executors</span>.<span class="pl-s1">kubernetes_executor</span> <span class="pl-k">import</span> <span class="pl-v">KubernetesExecutor</span>  <span class="pl-c"># noqa</span>

   <span class="pl-s1">valid_kubernetes_config</span> <span class="pl-c1">=</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">executor</span>, <span class="pl-v">KubernetesExecutor</span>)
<span class="pl-k">except</span> <span class="pl-v">ImportError</span>:
   <span class="pl-k">pass</span>

<span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">valid_celery_config</span> <span class="pl-c1">and</span> <span class="pl-c1">not</span> <span class="pl-s1">valid_kubernetes_config</span>:
   <span class="pl-en">flash</span>(<span class="pl-s">"Only works with the Celery or Kubernetes executors, sorry"</span>, <span class="pl-s">"error"</span>)
   <span class="pl-k">return</span> <span class="pl-en">redirect</span>(<span class="pl-s1">origin</span>)</pre></div>
<p dir="auto">In there, bug in this code snippet</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="try:
  from airflow.contrib.executors.kubernetes_executor import KubernetesExecutor  # BUG IS HERE !!!

   valid_kubernetes_config = isinstance(executor, KubernetesExecutor)
except ImportError:
   pass"><pre class="notranslate"><span class="pl-k">try</span>:
  <span class="pl-k">from</span> <span class="pl-s1">airflow</span>.<span class="pl-s1">contrib</span>.<span class="pl-s1">executors</span>.<span class="pl-s1">kubernetes_executor</span> <span class="pl-k">import</span> <span class="pl-v">KubernetesExecutor</span>  <span class="pl-c"># BUG IS HERE !!!</span>

   <span class="pl-s1">valid_kubernetes_config</span> <span class="pl-c1">=</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">executor</span>, <span class="pl-v">KubernetesExecutor</span>)
<span class="pl-k">except</span> <span class="pl-v">ImportError</span>:
   <span class="pl-k">pass</span></pre></div>
<p dir="auto">Import statement raises error KubernetesExecutor not found in this module because when you look that module at tag 1.10.12 <a href="https://github.com/apache/airflow/blob/1.10.12/airflow/contrib/executors/kubernetes_executor.py">https://github.com/apache/airflow/blob/1.10.12/airflow/contrib/executors/kubernetes_executor.py</a>, there is no KubernetesExecutor class, only includes kubernetes_executor module which it is KubernetesExecutor's location. But when you use that you need to change the code like that:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="try:
  from airflow.contrib.executors.kubernetes_executor import kubernetes_executor
  
  valid_kubernetes_config = isinstance(executor, kubernetes_executor.KubernetesExecutor)
except ImportError:
   pass"><pre class="notranslate"><span class="pl-k">try</span>:
  <span class="pl-k">from</span> <span class="pl-s1">airflow</span>.<span class="pl-s1">contrib</span>.<span class="pl-s1">executors</span>.<span class="pl-s1">kubernetes_executor</span> <span class="pl-k">import</span> <span class="pl-s1">kubernetes_executor</span>
  
  <span class="pl-s1">valid_kubernetes_config</span> <span class="pl-c1">=</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">executor</span>, <span class="pl-s1">kubernetes_executor</span>.<span class="pl-v">KubernetesExecutor</span>)
<span class="pl-k">except</span> <span class="pl-v">ImportError</span>:
   <span class="pl-k">pass</span></pre></div>
<p dir="auto">or:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="try:
  from airflow.executors.kubernetes_executor import KubernetesExecutor
  
  valid_kubernetes_config = isinstance(executor, KubernetesExecutor)
except ImportError:
   pass"><pre class="notranslate"><span class="pl-k">try</span>:
  <span class="pl-k">from</span> <span class="pl-s1">airflow</span>.<span class="pl-s1">executors</span>.<span class="pl-s1">kubernetes_executor</span> <span class="pl-k">import</span> <span class="pl-v">KubernetesExecutor</span>
  
  <span class="pl-s1">valid_kubernetes_config</span> <span class="pl-c1">=</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">executor</span>, <span class="pl-v">KubernetesExecutor</span>)
<span class="pl-k">except</span> <span class="pl-v">ImportError</span>:
   <span class="pl-k">pass</span></pre></div>
<p dir="auto"><strong>What you expected:</strong></p>
<p dir="auto">Runs successfully single task with KubernetesExecutor. This error block user to run single task with KubernetesExecutor without run whole DAG.</p>
<p dir="auto">Thanks, have a nice day <g-emoji class="g-emoji" alias="+1" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png">👍</g-emoji> <g-emoji class="g-emoji" alias="smile" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f604.png">😄</g-emoji></p>