uranusjr commented on a change in pull request #16352: URL: https://github.com/apache/airflow/pull/16352#discussion_r681400265
########## 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: `current_app.dag_bag.get_dag(dag_id)` returns a `DAG`, not a `DagModel`. only `DAG` can call `create_dagrun` (yes it’s a bit confusing, it took a while for me quite a while to sort these out). The new implementation matches more closely to how the Trigger Run web UI is doing. https://github.com/apache/airflow/blob/ff75cbcac9ec0b1992b4fddd6c160901f23e0c2a/airflow/www/views.py#L1570-L1621 -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org