You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "baolsen (via GitHub)" <gi...@apache.org> on 2025/03/24 19:54:29 UTC
[PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
baolsen opened a new pull request, #48214:
URL: https://github.com/apache/airflow/pull/48214
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
---
Add an optional parameter to `TriggerDagRunOperator` to allow it to check if the triggered DAG is in a Paused state, and if so then fail the task.
**^ Add meaningful description above**
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #48214:
URL: https://github.com/apache/airflow/pull/48214#discussion_r2046222580
##########
providers/standard/src/airflow/providers/standard/operators/trigger_dagrun.py:
##########
@@ -61,6 +61,7 @@
from airflow.utils.context import Context
if AIRFLOW_V_3_0_PLUS:
+ from airflow.exceptions import DagIsPaused
Review Comment:
Sure, I'm ok with it!
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
Posted by "baolsen (via GitHub)" <gi...@apache.org>.
baolsen commented on code in PR #48214:
URL: https://github.com/apache/airflow/pull/48214#discussion_r2042077770
##########
providers/standard/src/airflow/providers/standard/operators/trigger_dagrun.py:
##########
@@ -61,6 +61,7 @@
from airflow.utils.context import Context
if AIRFLOW_V_3_0_PLUS:
+ from airflow.exceptions import DagIsPaused
Review Comment:
Previously the CI was failing when it was testing Airflow 2.x, so I added this guard in here and on the tests where it can't import the new exception.
Though I'm not sure exactly how the backwards compatibility testing works.
Should I try removing it from here?
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #48214:
URL: https://github.com/apache/airflow/pull/48214#issuecomment-2808561650
cc @eladkal
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
Posted by "baolsen (via GitHub)" <gi...@apache.org>.
baolsen commented on PR #48214:
URL: https://github.com/apache/airflow/pull/48214#issuecomment-2800669894
@Lee-W thanks for the review. Who can I ask to help with merging these changes in?
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #48214:
URL: https://github.com/apache/airflow/pull/48214#issuecomment-2808561515
@Lee-W you ok with merging this one? Do you see any issues?
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #48214:
URL: https://github.com/apache/airflow/pull/48214#discussion_r2046211622
##########
providers/standard/src/airflow/providers/standard/operators/trigger_dagrun.py:
##########
@@ -61,6 +61,7 @@
from airflow.utils.context import Context
if AIRFLOW_V_3_0_PLUS:
+ from airflow.exceptions import DagIsPaused
Review Comment:
We could define the exception if `not` v3 plus. But I'm good with merge as it is if @jason810496 's also ok with it
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 merged PR #48214:
URL: https://github.com/apache/airflow/pull/48214
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on PR #48214:
URL: https://github.com/apache/airflow/pull/48214#issuecomment-2800673114
I'll keep it open for one or two days in case someone else wants to take a look. After that, I'll merge it
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on PR #48214:
URL: https://github.com/apache/airflow/pull/48214#issuecomment-2808574487
> @Lee-W you ok with merging this one? Do you see any issues?
LGTM on my end. minor issue. non-blocking
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #48214:
URL: https://github.com/apache/airflow/pull/48214#discussion_r2041964532
##########
providers/standard/src/airflow/providers/standard/operators/trigger_dagrun.py:
##########
@@ -61,6 +61,7 @@
from airflow.utils.context import Context
if AIRFLOW_V_3_0_PLUS:
+ from airflow.exceptions import DagIsPaused
Review Comment:
I think we can import the new `DagIsPaused` exception at the top level, rather than inside the `AIRFLOW_V_3_0_PLUS` specific block.
This shouldn't be a breaking change for Airflow 3, right?
cc @Lee-W
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #48214:
URL: https://github.com/apache/airflow/pull/48214#discussion_r2038898137
##########
airflow-core/src/airflow/exceptions.py:
##########
@@ -246,6 +246,17 @@ class AirflowTimetableInvalid(AirflowException):
"""Raise when a DAG has an invalid timetable."""
+class DagIsPaused(AirflowException):
+ """Raise when a DAG is paused and something tries to run it."""
Review Comment:
```suggestion
"""Raise when a dag is paused and something tries to run it."""
```
##########
airflow-core/src/airflow/exceptions.py:
##########
@@ -246,6 +246,17 @@ class AirflowTimetableInvalid(AirflowException):
"""Raise when a DAG has an invalid timetable."""
+class DagIsPaused(AirflowException):
+ """Raise when a DAG is paused and something tries to run it."""
+
+ def __init__(self, dag_id: str) -> None:
+ super().__init__(dag_id)
+ self.dag_id = dag_id
+
+ def __str__(self) -> str:
+ return f"DAG {self.dag_id} is paused"
Review Comment:
```suggestion
return f"Dag {self.dag_id} is paused"
```
##########
providers/standard/tests/unit/standard/operators/test_trigger_dagrun.py:
##########
@@ -734,3 +735,21 @@ def test_dagstatetrigger_run_id_with_clear_and_reset(self, dag_maker):
# The second DagStateTrigger call should still use the original `logical_date` value.
assert mock_task_defer.call_args_list[1].kwargs["trigger"].run_ids == [run_id]
+
+ def test_trigger_dagrun_with_fail_when_dag_is_paused(self, dag_maker):
+ """Test TriggerDagRunOperator with skip_when_already_exists."""
Review Comment:
```suggestion
"""Test TriggerDagRunOperator with fail_when_dag_is_paused set to True."""
```
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #48214:
URL: https://github.com/apache/airflow/pull/48214#discussion_r2041964532
##########
providers/standard/src/airflow/providers/standard/operators/trigger_dagrun.py:
##########
@@ -61,6 +61,7 @@
from airflow.utils.context import Context
if AIRFLOW_V_3_0_PLUS:
+ from airflow.exceptions import DagIsPaused
Review Comment:
I think we can import the new `DagIsPaused` exception in top level instead of `AIRFLOW_V_3_0_PLUS` specific block ?
cc @Lee-W
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Add fail_when_dag_is_paused param to TriggerDagRunOperator [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #48214:
URL: https://github.com/apache/airflow/pull/48214#discussion_r2037023281
##########
providers/standard/src/airflow/providers/standard/operators/trigger_dagrun.py:
##########
@@ -131,6 +131,7 @@ class TriggerDagRunOperator(BaseOperator):
Default is ``[DagRunState.FAILED]``.
:param skip_when_already_exists: Set to true to mark the task as SKIPPED if a DAG run of the triggered
DAG for the same logical date already exists.
+ :param fail_when_dag_is_paused: If the DAG to trigger is paused, fail the task.
Review Comment:
```suggestion
:param fail_when_dag_is_paused: If the dag to trigger is paused, fail the task.
```
##########
providers/standard/src/airflow/providers/standard/operators/trigger_dagrun.py:
##########
@@ -212,6 +215,11 @@ def execute(self, context: Context):
else:
run_id = DagRun.generate_run_id(DagRunType.MANUAL, parsed_logical_date or timezone.utcnow()) # type: ignore[misc,call-arg]
+ if self.fail_when_dag_is_paused:
+ dag_model = DagModel.get_current(self.trigger_dag_id)
+ if dag_model.is_paused:
+ raise AirflowException(f"Dag id {self.trigger_dag_id} is paused")
Review Comment:
Please create a custom exception instead of using AirflowException directly
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org