Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AIRFLOW-4482] Add execution_date to trigger DAG run API response #5260

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion airflow/www/api/experimental/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
12 changes: 10 additions & 2 deletions tests/www/api/experimental/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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'),
Expand All @@ -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)
Expand Down