kaxil commented on a change in pull request #8227:
URL: https://github.com/apache/airflow/pull/8227#discussion_r431313499



##########
File path: airflow/models/dag.py
##########
@@ -1468,14 +1472,26 @@ def create_dagrun(self,
         :param session: database session
         :type session: sqlalchemy.orm.session.Session
         """
+        if run_id:
+            if not isinstance(run_id, str):
+                raise ValueError(f"`run_id` expected to be a str is 
{type(run_id)}")
+            run_type: DagRunType = DagRunType.from_run_id(run_id)
+        elif run_type and execution_date:
+            run_id = DagRun.generate_run_id(run_type, execution_date)
+        elif not run_id:
+            raise AirflowException(
+                "Creating DagRun needs either `run_id` or `run_type` and 
`execution_date`"
+            )
+
         run = DagRun(
             dag_id=self.dag_id,
             run_id=run_id,
             execution_date=execution_date,
             start_date=start_date,
             external_trigger=external_trigger,
             conf=conf,
-            state=state
+            state=state,
+            run_type=run_type.value,

Review comment:
       If a string is passed to run_type this will fail with "not so helpful" 
error, e.g "string type has no attribute value".
   
   We should probably add a check to see if only `run_type` is of Enum type 
only.
   




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to