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

Add is_mapped field to Task response. #23319

Merged
merged 2 commits into from
Apr 28, 2022
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
3 changes: 3 additions & 0 deletions airflow/api_connexion/openapi/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3013,6 +3013,9 @@ components:
depends_on_past:
type: boolean
readOnly: true
is_mapped:
type: boolean
readOnly: true
wait_for_downstream:
type: boolean
readOnly: true
Expand Down
1 change: 1 addition & 0 deletions airflow/api_connexion/schemas/task_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class TaskSchema(Schema):
sub_dag = fields.Nested(DAGSchema, dump_only=True)
downstream_task_ids = fields.List(fields.String(), dump_only=True)
params = fields.Method('get_params', dump_only=True)
is_mapped = fields.Boolean(dump_only=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a field to the schema also requires adding it to the API definition in airflow/api_connexion/openapi/v1.yaml (line 2,938 onwards), so that it shows up in the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I though it was automatically generated. Added now.


def _get_class_reference(self, obj):
result = ClassReferenceSchema().dump(obj)
Expand Down
114 changes: 113 additions & 1 deletion tests/api_connexion/endpoints/test_task_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ def configured_app(minimal_app_for_api):

class TestTaskEndpoint:
dag_id = "test_dag"
mapped_dag_id = "test_mapped_task"
task_id = "op1"
task_id2 = 'op2'
task_id3 = "op3"
mapped_task_id = "mapped_task"
task1_start_date = datetime(2020, 6, 15)
task2_start_date = datetime(2020, 6, 16)

Expand All @@ -63,9 +66,13 @@ def setup_dag(self, configured_app):
task1 = EmptyOperator(task_id=self.task_id, params={'foo': 'bar'})
task2 = EmptyOperator(task_id=self.task_id2, start_date=self.task2_start_date)

with DAG(self.mapped_dag_id, start_date=self.task1_start_date) as mapped_dag:
task3 = EmptyOperator(task_id=self.task_id3) # noqa
mapped_task = EmptyOperator.partial(task_id=self.mapped_task_id).expand() # noqa

task1 >> task2
dag_bag = DagBag(os.devnull, include_examples=False)
dag_bag.dags = {dag.dag_id: dag}
dag_bag.dags = {dag.dag_id: dag, mapped_dag.dag_id: mapped_dag}
configured_app.dag_bag = dag_bag # type:ignore

@staticmethod
Expand Down Expand Up @@ -120,13 +127,48 @@ def test_should_respond_200(self):
"ui_fgcolor": "#000",
"wait_for_downstream": False,
"weight_rule": "downstream",
"is_mapped": False,
}
response = self.client.get(
f"/api/v1/dags/{self.dag_id}/tasks/{self.task_id}", environ_overrides={'REMOTE_USER': "test"}
)
assert response.status_code == 200
assert response.json == expected

def test_mapped_task(self):
expected = {
"class_ref": {"class_name": "EmptyOperator", "module_path": "airflow.operators.empty"},
"depends_on_past": False,
"downstream_task_ids": [],
"end_date": None,
"execution_timeout": None,
"extra_links": [],
"is_mapped": True,
"owner": "airflow",
"params": {},
"pool": "default_pool",
"pool_slots": 1.0,
"priority_weight": 1.0,
"queue": "default",
"retries": 0.0,
"retry_delay": {"__type": "TimeDelta", "days": 0, "microseconds": 0, "seconds": 300},
"retry_exponential_backoff": False,
"start_date": "2020-06-15T00:00:00+00:00",
"task_id": "mapped_task",
"template_fields": [],
"trigger_rule": "all_success",
"ui_color": "#e8f7e4",
"ui_fgcolor": "#000",
"wait_for_downstream": False,
"weight_rule": "downstream",
}
response = self.client.get(
f"/api/v1/dags/{self.mapped_dag_id}/tasks/{self.mapped_task_id}",
environ_overrides={'REMOTE_USER': "test"},
)
assert response.status_code == 200
assert response.json == expected

def test_should_respond_200_serialized(self):

# Get the dag out of the dagbag before we patch it to an empty one
Expand Down Expand Up @@ -170,6 +212,7 @@ def test_should_respond_200_serialized(self):
"ui_fgcolor": "#000",
"wait_for_downstream": False,
"weight_rule": "downstream",
"is_mapped": False,
}
response = self.client.get(
f"/api/v1/dags/{self.dag_id}/tasks/{self.task_id}", environ_overrides={'REMOTE_USER': "test"}
Expand Down Expand Up @@ -235,6 +278,7 @@ def test_should_respond_200(self):
"ui_fgcolor": "#000",
"wait_for_downstream": False,
"weight_rule": "downstream",
"is_mapped": False,
},
{
"class_ref": {
Expand Down Expand Up @@ -263,6 +307,7 @@ def test_should_respond_200(self):
"ui_fgcolor": "#000",
"wait_for_downstream": False,
"weight_rule": "downstream",
"is_mapped": False,
},
],
"total_entries": 2,
Expand All @@ -273,6 +318,73 @@ def test_should_respond_200(self):
assert response.status_code == 200
assert response.json == expected

def test_get_tasks_mapped(self):
expected = {
"tasks": [
{
"class_ref": {"class_name": "EmptyOperator", "module_path": "airflow.operators.empty"},
"depends_on_past": False,
"downstream_task_ids": [],
"end_date": None,
"execution_timeout": None,
"extra_links": [],
"is_mapped": True,
"owner": "airflow",
"params": {},
"pool": "default_pool",
"pool_slots": 1.0,
"priority_weight": 1.0,
"queue": "default",
"retries": 0.0,
"retry_delay": {"__type": "TimeDelta", "days": 0, "microseconds": 0, "seconds": 300},
"retry_exponential_backoff": False,
"start_date": "2020-06-15T00:00:00+00:00",
"task_id": "mapped_task",
"template_fields": [],
"trigger_rule": "all_success",
"ui_color": "#e8f7e4",
"ui_fgcolor": "#000",
"wait_for_downstream": False,
"weight_rule": "downstream",
},
{
"class_ref": {
"class_name": "EmptyOperator",
"module_path": "airflow.operators.empty",
},
"depends_on_past": False,
"downstream_task_ids": [],
"end_date": None,
"execution_timeout": None,
"extra_links": [],
"owner": "airflow",
"params": {},
"pool": "default_pool",
"pool_slots": 1.0,
"priority_weight": 1.0,
"queue": "default",
"retries": 0.0,
"retry_delay": {"__type": "TimeDelta", "days": 0, "seconds": 300, "microseconds": 0},
"retry_exponential_backoff": False,
"start_date": "2020-06-15T00:00:00+00:00",
"task_id": self.task_id3,
"template_fields": [],
"trigger_rule": "all_success",
"ui_color": "#e8f7e4",
"ui_fgcolor": "#000",
"wait_for_downstream": False,
"weight_rule": "downstream",
"is_mapped": False,
},
],
"total_entries": 2,
}
response = self.client.get(
f"/api/v1/dags/{self.mapped_dag_id}/tasks", environ_overrides={'REMOTE_USER': "test"}
)
assert response.status_code == 200
assert response.json == expected

def test_should_respond_200_ascending_order_by_start_date(self):
response = self.client.get(
f"/api/v1/dags/{self.dag_id}/tasks?order_by=start_date",
Expand Down
2 changes: 2 additions & 0 deletions tests/api_connexion/schemas/test_task_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def test_serialize(self):
"ui_fgcolor": "#000",
"wait_for_downstream": False,
"weight_rule": "downstream",
"is_mapped": False,
}
assert expected == result

Expand Down Expand Up @@ -101,6 +102,7 @@ def test_serialize(self):
"ui_fgcolor": "#000",
"wait_for_downstream": False,
"weight_rule": "downstream",
"is_mapped": False,
}
],
"total_entries": 1,
Expand Down