ashb commented on code in PR #45961:
URL: https://github.com/apache/airflow/pull/45961#discussion_r1928387183
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -1476,14 +1476,18 @@ def _update_state(dag: DAG, dag_run: DagRun):
dag_run.state = DagRunState.RUNNING
dag_run.start_date = timezone.utcnow()
- if dag.timetable.periodic and not dag_run.external_trigger and
dag_run.clear_number < 1:
+ if (
+ dag.timetable.periodic
+ and not dag_run.run_type == DagRunType.MANUAL
Review Comment:
```suggestion
and dag_run.run_type != DagRunType.MANUAL
```
##########
airflow/utils/db_cleanup.py:
##########
@@ -107,9 +107,9 @@ def readable_config(self):
_TableConfig(
table_name="dag_run",
recency_column_name="start_date",
- extra_columns=["dag_id", "external_trigger"],
+ extra_columns=["dag_id", "run_type"],
keep_last=True,
- keep_last_filters=[column("external_trigger") == false()],
+ keep_last_filters=[column("run_type") != "manual"],
Review Comment:
We shouldn't use a string literal here but the enum constant please.
##########
airflow/example_dags/plugins/event_listener.py:
##########
@@ -147,9 +147,8 @@ def on_dag_run_failed(dag_run: DagRun, msg: str):
print("Dag run in failure state")
dag_id = dag_run.dag_id
run_id = dag_run.run_id
- external_trigger = dag_run.external_trigger
- print(f"Dag information:{dag_id} Run id: {run_id} external trigger:
{external_trigger}")
+ print(f"Dag information:{dag_id} Run id: {run_id}")
Review Comment:
Not that it _matters_, but lets include the run_type here in its place.
##########
airflow/migrations/versions/0056_3_0_0_remove_external_trigger_field.py:
##########
@@ -0,0 +1,56 @@
+#
+# 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.
+
+"""
+remove external_trigger field.
+
+Revision ID: fbe8516980a3
+Revises: e39a26ac59f6
+Create Date: 2025-01-23 09:53:31.283015
+
+"""
+
+from __future__ import annotations
+
+import sqlalchemy as sa
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision = "fbe8516980a3"
+down_revision = "e39a26ac59f6"
+branch_labels = None
+depends_on = None
+airflow_version = "3.0.0"
+
+
+def upgrade():
+ """Apply remove external_trigger field."""
+ # ### commands auto generated by Alembic - please adjust! ###
+ with op.batch_alter_table("dag_run", schema=None) as batch_op:
+ batch_op.drop_column("external_trigger")
+
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ """Unapply remove external_trigger field."""
+ # ### commands auto generated by Alembic - please adjust! ###
+ with op.batch_alter_table("dag_run", schema=None) as batch_op:
+ batch_op.add_column(sa.Column("external_trigger", sa.BOOLEAN(),
autoincrement=False, nullable=True))
+
+ # ### end Alembic commands ###
Review Comment:
```suggestion
```
##########
airflow/migrations/versions/0056_3_0_0_remove_external_trigger_field.py:
##########
@@ -0,0 +1,56 @@
+#
+# 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.
+
+"""
+remove external_trigger field.
+
+Revision ID: fbe8516980a3
+Revises: e39a26ac59f6
+Create Date: 2025-01-23 09:53:31.283015
+
+"""
+
+from __future__ import annotations
+
+import sqlalchemy as sa
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision = "fbe8516980a3"
+down_revision = "e39a26ac59f6"
+branch_labels = None
+depends_on = None
+airflow_version = "3.0.0"
+
+
+def upgrade():
+ """Apply remove external_trigger field."""
+ # ### commands auto generated by Alembic - please adjust! ###
+ with op.batch_alter_table("dag_run", schema=None) as batch_op:
+ batch_op.drop_column("external_trigger")
+
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ """Unapply remove external_trigger field."""
+ # ### commands auto generated by Alembic - please adjust! ###
Review Comment:
```suggestion
```
##########
airflow/migrations/versions/0056_3_0_0_remove_external_trigger_field.py:
##########
@@ -0,0 +1,56 @@
+#
+# 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.
+
+"""
+remove external_trigger field.
+
+Revision ID: fbe8516980a3
+Revises: e39a26ac59f6
+Create Date: 2025-01-23 09:53:31.283015
+
+"""
+
+from __future__ import annotations
+
+import sqlalchemy as sa
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision = "fbe8516980a3"
+down_revision = "e39a26ac59f6"
+branch_labels = None
+depends_on = None
+airflow_version = "3.0.0"
+
+
+def upgrade():
+ """Apply remove external_trigger field."""
+ # ### commands auto generated by Alembic - please adjust! ###
+ with op.batch_alter_table("dag_run", schema=None) as batch_op:
+ batch_op.drop_column("external_trigger")
+
+ # ### end Alembic commands ###
Review Comment:
```suggestion
```
##########
providers/tests/openlineage/plugins/test_adapter.py:
##########
@@ -585,9 +586,8 @@ def test_emit_dag_started_event(mock_stats_incr,
mock_stats_timer, generate_stat
"dag_id": "dag_id",
"data_interval_start": event_time.isoformat(),
"data_interval_end": event_time.isoformat(),
- "external_trigger": False if AIRFLOW_V_3_0_PLUS else None,
"run_id": run_id,
- "run_type": None,
+ "run_type": DagRunType.MANUAL if AIRFLOW_V_3_0_PLUS else None,
Review Comment:
```suggestion
"run_type": DagRunType.MANUAL,
```
run_type has been around for _a long time_, we don't need this switch I
don't think?
##########
providers/src/airflow/providers/standard/operators/latest_only.py:
##########
@@ -53,7 +54,7 @@ def choose_branch(self, context: Context) -> str |
Iterable[str]:
# If the DAG Run is externally triggered, then return without
# skipping downstream tasks
dag_run: DagRun = context["dag_run"] # type: ignore[assignment]
- if dag_run.external_trigger:
+ if dag_run.run_type == DagRunType.MANUAL:
Review Comment:
Ditto here about BACKFILL. Need to decide how to handle this
##########
airflow/migrations/versions/0056_3_0_0_remove_external_trigger_field.py:
##########
@@ -0,0 +1,56 @@
+#
+# 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.
+
+"""
+remove external_trigger field.
+
+Revision ID: fbe8516980a3
+Revises: e39a26ac59f6
+Create Date: 2025-01-23 09:53:31.283015
+
+"""
+
+from __future__ import annotations
+
+import sqlalchemy as sa
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision = "fbe8516980a3"
+down_revision = "e39a26ac59f6"
+branch_labels = None
+depends_on = None
+airflow_version = "3.0.0"
+
+
+def upgrade():
+ """Apply remove external_trigger field."""
+ # ### commands auto generated by Alembic - please adjust! ###
Review Comment:
```suggestion
```
##########
providers/src/airflow/providers/standard/operators/latest_only.py:
##########
@@ -53,7 +54,7 @@ def choose_branch(self, context: Context) -> str |
Iterable[str]:
# If the DAG Run is externally triggered, then return without
# skipping downstream tasks
dag_run: DagRun = context["dag_run"] # type: ignore[assignment]
- if dag_run.external_trigger:
+ if dag_run.run_type == DagRunType.MANUAL:
self.log.info("Externally triggered DAG_Run: allowing execution to
proceed.")
Review Comment:
This message is wrong now
##########
airflow/models/dagrun.py:
##########
@@ -1227,11 +1217,11 @@ def
_emit_true_scheduling_delay_stats_for_finished_state(self, finished_tis: lis
rid of the outliers on the stats side through dashboards tooling.
Note that the stat will only be emitted for scheduler-triggered DAG
runs
- (i.e. when ``external_trigger`` is *False* and ``clear_number`` is
equal to 0).
+ (i.e. when ``run_type`` is *MANUAL* and ``clear_number`` is equal to
0).
Review Comment:
```suggestion
(i.e. when ``run_type`` is not *MANUAL* and ``clear_number`` is
equal to 0).
```
Though this brings up another question: How should this function deal with
run_type==BACKFILL?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]