<h3 dir="auto">Apache Airflow version</h3>
<p dir="auto">2.2.3</p>
<h3 dir="auto">What happened</h3>
<p dir="auto">When a task instance is in a failed state (or any other non running state), and then it's marked as successful through the UI, the <code class="notranslate">on_success_callback</code> set on the task instance is not run.</p>
<h3 dir="auto">What you think should happen instead</h3>
<p dir="auto">The <code class="notranslate">on_success_callback</code> should run when marking a task instance successful from the UI regardless of its state.</p>
<h3 dir="auto">How to reproduce</h3>
<ol dir="auto">
<li>Create a DAG</li>
<li>Add a task with an <code class="notranslate">on_success_callback</code> that throws an exception (so it fails)</li>
<li>Run the DAG in the UI</li>
<li>Wait for the task instance to fail for that DAG run</li>
<li>Mark the task instance successful in the UI for that DAG run</li>
</ol>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Debian 10 (Buster)</p>
<h3 dir="auto">Versions of Apache Airflow Providers</h3>
<p dir="auto"><code class="notranslate">apache-airflow-providers-databricks==2.5.0</code></p>
<p dir="auto">This is the main provider we care about at the moment.</p>
<h3 dir="auto">Deployment</h3>
<p dir="auto">Other Docker-based deployment</p>
<h3 dir="auto">Anything else</h3>
<p dir="auto">From my observations, it seems as though the <code class="notranslate">on_success_callback</code> <em>is</em> run when a task instance is in a <code class="notranslate">RUNNING</code> state, and then is marked successful from the UI, but not when the task instance is in any other state. From some brief digging this behaviour appears to be related to <a href="https://github.com/apache/airflow/blob/e09b4f144d1edefad50a58ebef56bd40df4eb39c/airflow/jobs/local_task_job.py#L236">the <code class="notranslate">heartbeat_callback</code></a> based on <a href="https://issues.apache.org/jira/browse/AIRFLOW-6821" rel="nofollow">this old bug report</a> but I can't see any equivalent logic for when the task <em>isn't</em> running.</p>
<p dir="auto">For context - we are using this behaviour to track issues occurring in Airflow with a 3rd party tool where marking a task instance as successful is effectively an "ignore", and our <code class="notranslate">on_success_callback</code> lets us register that ignore to another tool that tracks alerting.</p>
<h3 dir="auto">Are you willing to submit PR?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Yes I am willing to submit a PR!</li>
</ul>
<h3 dir="auto">Code of Conduct</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow this project's <a href="https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md">Code of Conduct</a></li>
</ul>
<h3 dir="auto">Apache Airflow version</h3>
<p dir="auto">2.1.1</p>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Ubuntu 20.04.3 LTS</p>
<h3 dir="auto">Versions of Apache Airflow Providers</h3>
<p dir="auto">apache-airflow-providers-amazon==2.0.0<br>
apache-airflow-providers-celery==2.0.0<br>
apache-airflow-providers-cncf-kubernetes==2.0.0<br>
apache-airflow-providers-databricks==2.0.0<br>
apache-airflow-providers-ftp==2.0.0<br>
apache-airflow-providers-imap==2.0.0<br>
apache-airflow-providers-mysql==2.0.0<br>
apache-airflow-providers-postgres==2.0.0<br>
apache-airflow-providers-redis==2.0.0<br>
apache-airflow-providers-sqlite==2.0.0<br>
apache-airflow-providers-ssh==2.0.0</p>
<h3 dir="auto">Deployment</h3>
<p dir="auto">Virtualenv installation</p>
<h3 dir="auto">Deployment details</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">What happened</h3>
<p dir="auto">'on_success_callback' and 'on_failure_callback' functions were not called when manually marking success or failure on a completed dag run.</p>
<h3 dir="auto">What you expected to happen</h3>
<p dir="auto">'on_success_callback' and 'on_failure_callback' functions should be called whenever marking success or failure on a dag run even after it completes.</p>
<h3 dir="auto">How to reproduce</h3>
<p dir="auto">Provide callback function as 'on_success_callback' argument when initializing DAG operator. Let one dag run complete. Check if 'on_success_callback' function is called. Then mark the dag run as failed. Then mark the dag run as succeeded. The 'on_success_callback' function is not called.</p>
<h3 dir="auto">Anything else</h3>
<p dir="auto">The callback functions are called when a dagrun is automatically marked success/failure by scheduler but aren't called when manually setting them after run completion. I have read earlier posts on stack overflow that this was not intended behaviour in Airflow 1 but could not find similar posts for Airflow 2 if this is a bug and how to fix it.</p>
<h3 dir="auto">Are you willing to submit PR?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Yes I am willing to submit a PR!</li>
</ul>
<h3 dir="auto">Code of Conduct</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow this project's <a href="https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md">Code of Conduct</a></li>
</ul>