Skip to content

Conversation

@m1racoli
Copy link
Contributor

@m1racoli m1racoli commented Oct 2, 2025

There are instances when AzureDataFactoryOperator in deferrable mode fails with the following error:

[2025-09-28 09:34:12] ERROR - Task failed with exception source=task loc=task_runner.py:972
AirflowException: (PipelineRunNotRunning) Pipeline run has already completed with status 'Succeeded'.Only pipeline runs that are in progress or queued can be canceled.
Code: PipelineRunNotRunning
Message: Pipeline run has already completed with status 'Succeeded'.Only pipeline runs that are in progress or queued can be canceled.
File "/usr/local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 920 in run

File "/usr/local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1307 in _execute_task

File "/usr/local/lib/python3.12/site-packages/airflow/sdk/bases/operator.py", line 1632 in resume_execution

File "/usr/local/lib/python3.12/site-packages/airflow/providers/microsoft/azure/operators/data_factory.py", line 256 in execute_complete

Unfortunately this error is only a result of another error resulting in an attempt to cancel an existing pipeline run. The shown error message indicates that this attempt failed, because the run itself was already successful. Unfortunately that second error is the only error reported back to the operator even though it is not the initial cause of failure (which is unknown).

This PR addresses this by:

  • logging the initial error with stacktrace in the trigger
  • in case of failure when cancelling the second error is only logged, while the initial error will be reported back to the operator as a failure reason

Additionally we do not obfuscate the exception when cancelling fails, such that we get better visibility on the actual exception thrown, which may allow us to handle failed cancellations for already successful pipelines more gracefully in the future.

Wrapping the exception AirflowException serves no real purpose and
obscures the original exception for downstream handling.
Although the exception text is passed back to the operator, we lose the
stack trace while doing so. By logging the exception in the trigger first,
we will get full details about where the exception happened.
When we fail to cancel a pipeline run after an unexpected error, we are
overriding the actual exception which caused the failure in first place.

This change addresses this by keeping the original exception untouched
and instead log any exception that occurs during the cancellation attempt.
@potiuk potiuk merged commit dafc960 into apache:main Oct 13, 2025
80 checks passed
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 14, 2025
* fix: don't wrap exception in AirflowException

Wrapping the exception AirflowException serves no real purpose and
obscures the original exception for downstream handling.

* fix: do log the actual exception in the trigger

Although the exception text is passed back to the operator, we lose the
stack trace while doing so. By logging the exception in the trigger first,
we will get full details about where the exception happened.

* fix: don't override original exception when cancelling ADF pipeline run

When we fail to cancel a pipeline run after an unexpected error, we are
overriding the actual exception which caused the failure in first place.

This change addresses this by keeping the original exception untouched
and instead log any exception that occurs during the cancellation attempt.

* Update providers/microsoft/azure/src/airflow/providers/microsoft/azure/triggers/data_factory.py

Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>

* refactor: remove unused exception

---------

Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>
@dstandish dstandish changed the title improve exception handling in AzureDataFactoryTrigger Improve exception handling in AzureDataFactoryTrigger Oct 14, 2025
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 15, 2025
* fix: don't wrap exception in AirflowException

Wrapping the exception AirflowException serves no real purpose and
obscures the original exception for downstream handling.

* fix: do log the actual exception in the trigger

Although the exception text is passed back to the operator, we lose the
stack trace while doing so. By logging the exception in the trigger first,
we will get full details about where the exception happened.

* fix: don't override original exception when cancelling ADF pipeline run

When we fail to cancel a pipeline run after an unexpected error, we are
overriding the actual exception which caused the failure in first place.

This change addresses this by keeping the original exception untouched
and instead log any exception that occurs during the cancellation attempt.

* Update providers/microsoft/azure/src/airflow/providers/microsoft/azure/triggers/data_factory.py

Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>

* refactor: remove unused exception

---------

Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 17, 2025
* fix: don't wrap exception in AirflowException

Wrapping the exception AirflowException serves no real purpose and
obscures the original exception for downstream handling.

* fix: do log the actual exception in the trigger

Although the exception text is passed back to the operator, we lose the
stack trace while doing so. By logging the exception in the trigger first,
we will get full details about where the exception happened.

* fix: don't override original exception when cancelling ADF pipeline run

When we fail to cancel a pipeline run after an unexpected error, we are
overriding the actual exception which caused the failure in first place.

This change addresses this by keeping the original exception untouched
and instead log any exception that occurs during the cancellation attempt.

* Update providers/microsoft/azure/src/airflow/providers/microsoft/azure/triggers/data_factory.py

Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>

* refactor: remove unused exception

---------

Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 19, 2025
* fix: don't wrap exception in AirflowException

Wrapping the exception AirflowException serves no real purpose and
obscures the original exception for downstream handling.

* fix: do log the actual exception in the trigger

Although the exception text is passed back to the operator, we lose the
stack trace while doing so. By logging the exception in the trigger first,
we will get full details about where the exception happened.

* fix: don't override original exception when cancelling ADF pipeline run

When we fail to cancel a pipeline run after an unexpected error, we are
overriding the actual exception which caused the failure in first place.

This change addresses this by keeping the original exception untouched
and instead log any exception that occurs during the cancellation attempt.

* Update providers/microsoft/azure/src/airflow/providers/microsoft/azure/triggers/data_factory.py

Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>

* refactor: remove unused exception

---------

Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>
TyrellHaywood pushed a commit to TyrellHaywood/airflow that referenced this pull request Oct 22, 2025
* fix: don't wrap exception in AirflowException

Wrapping the exception AirflowException serves no real purpose and
obscures the original exception for downstream handling.

* fix: do log the actual exception in the trigger

Although the exception text is passed back to the operator, we lose the
stack trace while doing so. By logging the exception in the trigger first,
we will get full details about where the exception happened.

* fix: don't override original exception when cancelling ADF pipeline run

When we fail to cancel a pipeline run after an unexpected error, we are
overriding the actual exception which caused the failure in first place.

This change addresses this by keeping the original exception untouched
and instead log any exception that occurs during the cancellation attempt.

* Update providers/microsoft/azure/src/airflow/providers/microsoft/azure/triggers/data_factory.py

Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>

* refactor: remove unused exception

---------

Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants