diff --git a/airflow/www/api/experimental/endpoints.py b/airflow/www/api/experimental/endpoints.py index 9a47a3559b449c..bac64fbbfcd04f 100644 --- a/airflow/www/api/experimental/endpoints.py +++ b/airflow/www/api/experimental/endpoints.py @@ -88,7 +88,7 @@ def trigger_dag(dag_id): if getattr(g, 'user', None): _log.info("User %s created %s", g.user, dr) - response = jsonify(message="Created {}".format(dr)) + response = jsonify(message="Created {}".format(dr), execution_date=dr.execution_date.isoformat()) return response diff --git a/tests/www/api/experimental/test_endpoints.py b/tests/www/api/experimental/test_endpoints.py index 39bc88a0083000..31013badf985fb 100644 --- a/tests/www/api/experimental/test_endpoints.py +++ b/tests/www/api/experimental/test_endpoints.py @@ -28,7 +28,7 @@ from airflow.api.common.experimental.trigger_dag import trigger_dag from airflow.models import DagBag, DagRun, Pool, TaskInstance from airflow.settings import Session -from airflow.utils.timezone import datetime, utcnow +from airflow.utils.timezone import datetime, utcnow, parse as parse_datetime from airflow.www import app as application @@ -122,13 +122,20 @@ def test_task_paused(self): def test_trigger_dag(self): url_template = '/api/experimental/dags/{}/dag_runs' + run_id = 'my_run' + utcnow().isoformat() response = self.client.post( url_template.format('example_bash_operator'), - data=json.dumps({'run_id': 'my_run' + utcnow().isoformat()}), + data=json.dumps({'run_id': run_id}), content_type="application/json" ) self.assertEqual(200, response.status_code) + # Check execution_date is correct + response = json.loads(response.data.decode('utf-8')) + dagbag = DagBag() + dag = dagbag.get_dag('example_bash_operator') + dag_run = dag.get_dagrun(parse_datetime(response['execution_date'])) + self.assertEqual(run_id, dag_run.run_id) response = self.client.post( url_template.format('does_not_exist_dag'), @@ -154,6 +161,7 @@ def test_trigger_dag_for_date(self): content_type="application/json" ) self.assertEqual(200, response.status_code) + self.assertEqual(datetime_string, json.loads(response.data.decode('utf-8'))['execution_date']) dagbag = DagBag() dag = dagbag.get_dag(dag_id)