houqp commented on a change in pull request #7133: [AIRFLOW-6535] add exception to fail without retry URL: https://github.com/apache/airflow/pull/7133#discussion_r370790466
########## File path: airflow/models/taskinstance.py ########## @@ -1120,10 +1125,33 @@ def handle_failure(self, error, test_mode=None, context=None, session=None): # only mark task instance as FAILED if the next task instance # try_number exceeds the max_tries. if self.is_eligible_to_retry(): - self.state = State.UP_FOR_RETRY - self.log.info('Marking task as UP_FOR_RETRY') - if task.email_on_retry and task.email: - self.email_alert(error) + if not force_fail: Review comment: perhaps we can make this if else combo less nested to reduce the complexity: ```python if not force_fail and self.is_eligible_to_retry(): self.state = State.UP_FOR_RETRY ... else: if force_fail: info_msg = "Immediate failure requested; skipping retries and marking task as FAILED." elif task.retries: info_msg = "All retries failed; marking task as FAILED." else: info_msg = "Marking task as FAILED." self.log.info("%s.\ndag_id=%s, task_id=%s, execution_date=%s, start_date=%s, end_date=%s", info_msg, ...) if task.email_on_failure and task.email: self.email_alert(error) ``` I think it's reasonable to not check `task.retries` when force_fail is set and always show `Immediate failure requested; skipping retries and marking task as FAILED.`. If you still want to keep it, we can add that in `if force_fail` block. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services