|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +from __future__ import annotations |
| 18 | + |
| 19 | +from datetime import datetime |
| 20 | + |
| 21 | +from airflow.sdk import DAG, BaseOperator, get_parsing_context |
| 22 | + |
| 23 | +DAG_ID = "dag_parsing_context_test" |
| 24 | + |
| 25 | +current_dag_id = get_parsing_context().dag_id |
| 26 | + |
| 27 | +with DAG( |
| 28 | + DAG_ID, |
| 29 | + start_date=datetime(2024, 2, 21), |
| 30 | + schedule=None, |
| 31 | +) as the_dag: |
| 32 | + BaseOperator(task_id="visible_task") |
| 33 | + |
| 34 | + if current_dag_id == DAG_ID: |
| 35 | + # this task will be invisible if the DAG ID is not properly set in the parsing context. |
| 36 | + BaseOperator(task_id="conditional_task") |
0 commit comments