uranusjr commented on a change in pull request #16352:
URL: https://github.com/apache/airflow/pull/16352#discussion_r657823002
##########
File path: airflow/models/dag.py
##########
@@ -1812,19 +1815,40 @@ def create_dagrun(
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:
+
+ # The preferred signature *requires* the data_interval argument. The
+ # legacy form of accepting an optional execution_date (and disallowing
+ # data_interval) is deprecated but accepted for compatibility.
+ if data_interval is None:
+ warnings.warn(
+ "Creating a DagRun without data_interval is deprecated.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ if execution_date is None:
+ start = timezone.utcnow()
+ else:
+ start = execution_date
+ if run_type == DagRunType.MANUAL:
+ data_interval = (start, start)
+ else:
+ data_interval = (start, self.following_schedule(start))
+ elif execution_date is not None:
+ raise TypeError("cannot set data_interval and execution_date
together")
+
+ if not run_id:
+ if not run_type or not data_interval:
+ raise AirflowException(
+ "Creating DagRun needs either `run_id` or both `run_type`
and `data_interval`"
+ )
if not isinstance(run_type, DagRunType):
raise ValueError(f"`run_type` expected to be a DagRunType is
{type(run_type)}")
- run_id = DagRun.generate_run_id(run_type, execution_date)
- elif not run_id:
- raise AirflowException(
- "Creating DagRun needs either `run_id` or both `run_type` and
`execution_date`"
- )
+ run_id = DagRun.generate_run_id(run_type, data_interval[0])
run = DagRun(
dag_id=self.dag_id,
run_id=run_id,
- execution_date=execution_date,
Review comment:
We should, I just haven’t reached that part yet.
--
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:
[email protected]