amoghrajesh commented on code in PR #54383:
URL: https://github.com/apache/airflow/pull/54383#discussion_r2299829895


##########
airflow-core/src/airflow/models/dagbag.py:
##########
@@ -143,6 +146,20 @@ def handle_timeout(signum, frame):
             signal.setitimer(signal.ITIMER_REAL, 0)
 
 
+def _validate_executor_fields(dag: DAG) -> None:
+    for task in dag.tasks:
+        if not task.executor:
+            continue
+        try:
+            ExecutorLoader.lookup_executor_name_by_str(task.executor)
+        except UnknownExecutorException:
+            raise UnknownExecutorException(
+                f"The specified executor {task.executor} for task 
{task.task_id} is not "
+                "configured. Review the core.executors Airflow configuration 
to add it or "
+                "update the executor configuration for this task."
+            )

Review Comment:
   ```suggestion
               raise UnknownExecutorException(
                   f"Task '{task.task_id}' specifies executor 
'{task.executor}', which is not available. "
                   "Make sure it is listed in your [core] executors 
configuration, or update the task's "
                   "executor to one of the configured executors."
               )
   ```
   
   Slightly clearer, nit



##########
airflow-core/src/airflow/serialization/serialized_objects.py:
##########
@@ -608,12 +622,12 @@ class BaseSerialization:
     SERIALIZER_VERSION = 2
 
     @classmethod
-    def to_json(cls, var: DAG | SchedulerOperator | dict | list | set | tuple) 
-> str:
+    def to_json(cls, var: Any) -> str:

Review Comment:
   Is the type relaxation intentional?



##########
airflow-core/src/airflow/cli/commands/task_command.py:
##########
@@ -429,25 +431,38 @@ def task_test(args, dag: DAG | None = None) -> None:
 def task_render(args, dag: DAG | None = None) -> None:
     """Render and displays templated fields for a given task."""
     if not dag:
-        dag = get_dag(args.bundle_name, args.dag_id)
-    # TODO (GH-52141): get_task in scheduler needs to return scheduler types
-    # instead, but currently it inherits SDK's DAG.
-    task = cast("Operator", dag.get_task(task_id=args.task_id))
+        dag = get_bagged_dag(args.bundle_name, args.dag_id)
+    serialized_dag = 
SerializedDAG.deserialize_dag(SerializedDAG.serialize_dag(dag))

Review Comment:
   I always felt there should be an utility that does: `return 
SerializedDAG.deserialize_dag(SerializedDAG.serialize_dag(dag))`



##########
airflow-core/src/airflow/cli/commands/task_command.py:
##########
@@ -429,25 +431,38 @@ def task_test(args, dag: DAG | None = None) -> None:
 def task_render(args, dag: DAG | None = None) -> None:
     """Render and displays templated fields for a given task."""
     if not dag:
-        dag = get_dag(args.bundle_name, args.dag_id)
-    # TODO (GH-52141): get_task in scheduler needs to return scheduler types
-    # instead, but currently it inherits SDK's DAG.
-    task = cast("Operator", dag.get_task(task_id=args.task_id))
+        dag = get_bagged_dag(args.bundle_name, args.dag_id)
+    serialized_dag = 
SerializedDAG.deserialize_dag(SerializedDAG.serialize_dag(dag))
     ti, _ = _get_ti(
-        task, args.map_index, 
logical_date_or_run_id=args.logical_date_or_run_id, create_if_necessary="memory"
+        # TODO (GH-52141): get_task in scheduler needs to return scheduler 
types
+        # instead, but currently it inherits SDK's DAG.
+        cast("Operator", serialized_dag.get_task(task_id=args.task_id)),

Review Comment:
   So right now it returns a `BaseOperator | MappedOperator` and we eventually 
expect it to return `SerializedBasedOperator` or similar?



##########
airflow-core/src/airflow/serialization/serialized_objects.py:
##########
@@ -669,7 +683,7 @@ def _is_excluded(cls, var: Any, attrname: str, instance: 
Any) -> bool:
     def serialize_to_json(
         cls,
         # TODO (GH-52141): When can we remove scheduler constructs here?
-        object_to_serialize: SdkOperator | SchedulerOperator | SdkDag | DAG,
+        object_to_serialize: SdkOperator | SchedulerOperator | DAG | 
SerializedDAG,

Review Comment:
   Maybe we can call the `SchedulerOperater` as `SerializedOperator` for 
clarity sake?



##########
airflow-core/tests/unit/cli/commands/test_dag_command.py:
##########
@@ -951,15 +954,18 @@ def test_dag_test_with_mark_success(self, 
mock__execute_task):
     @conf_vars({("core", "load_examples"): "false"})
     def test_get_dag_excludes_examples_with_bundle(self, 
configure_testing_dag_bundle):
         """Test that example DAGs are excluded when bundle names are passed."""
-        from airflow.utils.cli import get_dag
+        try:
+            from airflow.utils.cli import get_bagged_dag
+        except ImportError:  # Prior to Airflow 3.1.0.
+            from airflow.utils.cli import get_dag as get_bagged_dag  # type: 
ignore

Review Comment:
   We wont need compat here because its a core test? We could just do the `from 
airflow.utils.cli import get_bagged_dag` import always



##########
devel-common/src/tests_common/test_utils/dag.py:
##########
@@ -0,0 +1,66 @@
+#
+# 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.
+
+from __future__ import annotations
+
+from collections.abc import Iterable, Sequence
+from typing import TYPE_CHECKING
+
+from airflow.utils.session import NEW_SESSION, provide_session
+
+if TYPE_CHECKING:
+    from sqlalchemy.orm import Session
+
+    from airflow.sdk import DAG
+    from airflow.serialization.serialized_objects import SerializedDAG
+
+
+def create_scheduler_dag(dag: DAG | SerializedDAG) -> SerializedDAG:
+    from airflow.serialization.serialized_objects import SerializedDAG
+
+    if isinstance(dag, SerializedDAG):
+        return dag
+    return SerializedDAG.deserialize_dag(SerializedDAG.serialize_dag(dag))

Review Comment:
   Let's have this as an actual method instead of a test utility? I've seen 
this usage plenty to have an actual method



##########
devel-common/src/tests_common/pytest_plugin.py:
##########
@@ -982,14 +977,27 @@ def _make_serdag(self, dag):
                     SerializedDagModel.dag_hash == 
self.serialized_model.dag_hash,
                 )
             )
+
+            if AIRFLOW_V_3_0_PLUS:

Review Comment:
   v3.1 is a better check?



-- 
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]

Reply via email to