pierrejeambrun commented on code in PR #46512:
URL: https://github.com/apache/airflow/pull/46512#discussion_r1951222852
##########
airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -357,25 +357,38 @@ def trigger_dag_run(
f"DAG with dag_id: '{dag_id}' has import errors and cannot be
triggered",
)
- logical_date = timezone.coerce_datetime(body.logical_date)
- coerced_logical_date = timezone.coerce_datetime(logical_date)
-
+ logical_date = pendulum.instance(body.logical_date) if body.logical_date
else None
+ run_after = timezone.coerce_datetime(body.run_after)
try:
dag: DAG = request.app.state.dag_bag.get_dag(dag_id)
-
if body.data_interval_start and body.data_interval_end:
data_interval = DataInterval(
start=pendulum.instance(body.data_interval_start),
end=pendulum.instance(body.data_interval_end),
)
else:
- data_interval =
dag.timetable.infer_manual_data_interval(run_after=coerced_logical_date or now)
+ if body.logical_date:
+ data_interval = dag.timetable.infer_manual_data_interval(
+ run_after=timezone.coerce_datetime(body.logical_date)
+ )
+ run_after = data_interval.end
+ else:
+ data_interval = None
+
+ if body.dag_run_id:
+ run_id = body.dag_run_id
+ else:
Review Comment:
Ideally, all that validation logic for the payload should be moved to the
Serializer (pydantic model). It's just adding more LOC to the route definition,
and can't be re-used. (When the payload is loaded into a
`TriggerDAGRunPostBody` object, this object should be valid as is without
further validation/manipulation.
--
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]