uranusjr commented on a change in pull request #18724:
URL: https://github.com/apache/airflow/pull/18724#discussion_r783727049



##########
File path: airflow/models/dag.py
##########
@@ -1660,14 +1664,24 @@ def set_task_instance_state(
         :param past: Include all past TaskInstances of the given task_id
         :type past: bool
         """
-        from airflow.api.common.experimental.mark_tasks import set_state
+        from airflow.api.common.mark_tasks import set_state
+
+        if not exactly_one(execution_date, dag_run_id):
+            raise ValueError("Exactly one of execution_date or dag_run_id must 
be provided")
+        input_execution_date = execution_date
+        if dag_run_id:
+            dag_run = (
+                session.query(DagRun).filter(DagRun.run_id == dag_run_id, 
DagRun.dag_id == self.dag_id).one()
+            )  # Raises an error if not found
+            resolve_execution_date = dag_run.execution_date

Review comment:
       How about
   
   ```python
   if execution_date is None:
       dag_run = ...
       resolved_execution_date = dag_run.execution_date
   else:
       resolved_execution_date = execution_date
   ```
   
   This would simplify the later code to
   
   ```python
   end_date = resolve_execution_date if not future else None
   start_date = resolve_execution_date if not future else None
   ```




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