ephraimbuddy commented on a change in pull request #16352:
URL: https://github.com/apache/airflow/pull/16352#discussion_r681202782
##########
File path: airflow/api_connexion/endpoints/dag_run_endpoint.py
##########
@@ -242,21 +243,29 @@ def post_dag_run(dag_id, session):
except ValidationError as err:
raise BadRequest(detail=str(err))
+ execution_date = post_body["execution_date"]
+ run_id = post_body["run_id"]
dagrun_instance = (
session.query(DagRun)
.filter(
DagRun.dag_id == dag_id,
- or_(DagRun.run_id == post_body["run_id"], DagRun.execution_date ==
post_body["execution_date"]),
+ or_(DagRun.run_id == run_id, DagRun.execution_date ==
execution_date),
)
.first()
)
if not dagrun_instance:
- dag_run = DagRun(dag_id=dag_id, run_type=DagRunType.MANUAL,
**post_body)
- session.add(dag_run)
- session.commit()
+ dag_run = current_app.dag_bag.get_dag(dag_id).create_dagrun(
+ run_type=DagRunType.MANUAL,
+ run_id=run_id,
+ execution_date=execution_date,
+ state=State.QUEUED,
+ conf=post_body.get("conf"),
+ external_trigger=True,
+ dag_hash=current_app.dag_bag.dags_hash.get(dag_id),
+ )
Review comment:
In line 239 above, we queried the DagModel to check if dag exists. I'm
thinking that instead of `current_app.dag_bag.get_dag(dag_id).create_dagrun` we
should get dag from line 239:
```dag = session.query(DagModel).filter(DagModel.dag_id ==
dag_id).first()``` and then `dag.create_dagrun`, what do you think?
--
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]